2,886 views

What is printed by the following $\text{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;

}


1. $\begin {array}{} 1 & 2 & 3 \\ 10 & 11 & 12 \\ 19 & 20 & 21 \end{array}$
2. $\begin {array}{} 1 & 4 & 7 \\ 10 & 13 & 16 \\ 19 & 22 & 25 \end{array}$
3. $\begin {array}{} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array}$
4. $\begin {array}{} 1 & 2 & 3 \\ 13 & 14 & 15 \\ 25 & 26 & 27 \end{array}$

## 1 Answer

Best answer

Option A is correct

a is 3D array with size [3][3][3]

Therefore each 2D array contains 9 elements, we have 3 such arrays

0th 2D array have {1,2,3,4,5,6,7,8,9}

1st 2D array have {10,11,12,13,14,15,16,17,18}

2nd 2D array have {19,20,21,22,23,24,25,26,27}

each 2D array is collection of 1D array. we have 3 one dimensional arrays in one 2D

$\therefore \{\;\;{\underset{k=0,1,2\;\;}{\underbrace{1,2,3}}},\underset{k=0,1,2\;\;}{\underbrace{4,5,6}},\underset{k=0,1,2\;\;}{\underbrace{7,8,9}}\;\;\},$

$\{{\underset{k=0,1,2\;\;}{\underbrace{10,11,12}}},\underset{k=0,1,2\;\;}{\underbrace{13,14,15}},\underset{k=0,1,2\;\;}{\underbrace{16,17,18}\}},$

$\{{\underset{k=0,1,2\;\;}{\underbrace{19,20,21}}},\underset{k=0,1,2\;\;}{\underbrace{22,23,24}},\underset{k=0,1,2\;\;}{\underbrace{25,26,27}\}}$

when i=0, j=0, output = {1,2,3}

when i=1, j=0, output = {10,11,12}

when i=2, j=0, output = {19,20,21}

### 1 comment

SYNTAX of 3-D array : data_type arr[Block_size][row_size][column_size];

we can also solve this question by keeping in mind the above syntax :)

Answer:

12 votes
1 answer
1
3,798 views
7 votes
2 answers
2
2,299 views
3 votes
1 answer
3
350 views