Arrays
November 15, 2023Arrays
November 15, 2023Question 16143 – Arrays
What is printed by the following ANSI C program?
#include
{
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;
}
Correct Answer: A
Question 6 Explanation:
Array dimension sizes are 3,3,3 for all 3 dimensions hence, the value assigned to a[3] [3] [3] will be assigned from only first 3 indices i.e. 0^th, 1^st, & 2^nd and 3 dimensions shown by { }
Hence, 1, 2, 3 will be 1^st row
10 , 11, 12 will be 2^nd row
19, 20, 21 will be 3^rd row
Hence, 1, 2, 3 will be 1^st row
10 , 11, 12 will be 2^nd row
19, 20, 21 will be 3^rd row
1 2 3
10 11 12
19 20 21
10 11 12
19 20 21
1 4 7
10 13 16
19 22 25
10 13 16
19 22 25
1 2 3
4 5 6
7 8 9
4 5 6
7 8 9
1 2 3
13 14 15
25 26 27
13 14 15
25 26 27
Subscribe
Login
0 Comments