What is printed by the following ANSI C program?

#include<stdio.h>

int main(int argc, char *argv[])

{

int a[3][3][3] =

{{1, 2, 3, 4, 5, 6, 7, 8, 9},

{10, 11, 12, 13, 14, 15, 16, 17, 18},

{19, 20, 21, 22, 23, 24, 25, 26, 27}};

int i = 0, j = 0, k = 0;

for(i = 0; i < 3; i++ ){

for(k = 0; k < 3; k++ )

printf("%d ", a[i][j][k]);

printf("\n");

}

return 0;

This question was previously asked in
GATE CS 2022 Official Paper
View all GATE CS Papers >
  1. 1 2 3

    10 11 12

    19 20 21

  2. 1 4 7

    10 13 16

    19 22 25

  3. 1 2 3

    4 5 6

    7 8 9

  4. 1 2 3

    13 14 15

    25 26 27

Answer (Detailed Solution Below)

Option 1 :

1 2 3

10 11 12

19 20 21

Free
GATE CS Full Mock Test
5.3 K Users
65 Questions 100 Marks 180 Mins

Detailed Solution

Download Solution PDF

The correct answer is option 1.

Concept:

An array is defined as a collection of data items of the same type that are stored in contiguous memory locations. Arrays are derived data types in the C programming language that can store primitive data types such as int, char, double, float, and so on.

In C programming, you can create an array of arrays. These arrays are known as multidimensional arrays.

syntax:

int a[size1][size2][size3];

Total number of elements in array 'a' is= size1 x size2 x size 3

Three-dimensional array:

A three-dimensional array is a multi-dimensional array (array of arrays). A 3D array is made up of 2D arrays. Three subscripts are used to specify it: block size, row size, and column size. More dimensions in an array mean that it can store more data.

F1 Madhuri Engineering 28.03.2022 D37

Explanation:

  F1 Madhuri Engineering 28.03.2022 D38

a[0] 2 Dimension:

a[0][0][0]=1
a[0][0][1]=2
a[0][0][2]=3

a[0][1][0]=4
a[0][1][1]=5
a[0][1][2]=6

a[0][2][0]=7
a[0][2][1]=8
a[0][2][2]=9

a[1] 2 Dimension:
a[1][0][0]=10
a[1][0][1]=11
a[1][0][2]=12

a[1][1][0]=13
a[1][1][1]=14
a[1][1][2]=15

a[1][2][0]=16
a[1][2][1]=17
a[1][2][2]=18

a[2] 2 Dimension:
a[2][0][0]=19
a[2][0][1]=20
a[2][0][2]=21

a[2][1][0]=22
a[2][1][1]=23
a[2][1][2]=24

a[2][2][0]=25
a[2][2][1]=26
a[2][2][2]=27

The for loop has prints:

a[000] = 1 ,a [001] = 2, a[002] = 3, a[100] = 10, a[101] = 11, a[102] = 12, a[200] = 19, a[201] = 20, a[202] = 21

Hence the correct answer is 

1 2 3

10 11 12

19 20 21

Latest GATE CS Updates

Last updated on Jan 8, 2025

-> GATE CS 2025 Admit Card has been released on 7th January 2025.

-> The exam will be conducted on 1st February 2025 in 2 shifts.

-> Candidates applying for the GATE CE must satisfy the GATE Eligibility Criteria.

-> The candidates should have BTech (Computer Science). Candidates preparing for the exam can refer to the GATE CS Important Questions to improve their preparation.

-> Candidates must check their performance with the help of the GATE CS mock tests and GATE CS previous year papers for the GATE 2025 Exam.

Get Free Access Now
Hot Links: teen patti gold download dhani teen patti teen patti gold apk