GateAI
Programming in C

GATE CSE 2022 · Q43

MCQ2 marksMedium

Time

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(" "); } return 0; }

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) 1 2 3 10 11 12 19 20 21

Programming in C

The array a is a 3-dimensional array of shape 3×3×33 \times 3 \times 3, initialized as follows:

  1. First 2D block (a[0]):

    • a[0][0] = {1,2,3}\{1, 2, 3\}

    • a[0][1] = {4,5,6}\{4, 5, 6\}

    • a[0][2] = {7,8,9}\{7, 8, 9\}

  2. Second 2D block (a[1]):

    • a[1][0] = {10,11,12}\{10, 11, 12\}

    • a[1][1] = {13,14,15}\{13, 14, 15\}

    • a[1][2] = {16,17,18}\{16, 17, 18\}

  3. Third 2D block (a[2]):

    • a[2][0] = {19,20,21}\{19, 20, 21\}

    • a[2][1] = {22,23,24}\{22, 23, 24\}

    • a[2][2] = {25,26,27}\{25, 26, 27\}

In the nested loop, jj remains fixed at 00 throughout:

  • When i=0i = 0, kk ranges from 00 to 22, printing a[0][0][0], a[0][0][1], a[0][0][2], which gives: 1 2 3

  • When i=1i = 1, kk ranges from 00 to 22, printing a[1][0][0], a[1][0][1], a[1][0][2], which gives: 10 11 12

  • When i=2i = 2, kk ranges from 00 to 22, printing a[2][0][0], a[2][0][1], a[2][0][2], which gives: 19 20 21

Thus, the printed output matches (A).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Programming in C previous year question is Q43 of the GATE CSE 2022 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 19 of them are 2-mark MCQs like this one, and GATE CSE 2022 has 3.

How GATE tests Programming in C

More from GATE CSE 2022

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2022 · Q43 · MCQ

What is printed by the following ANSI C program? #include 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

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.