Skip to content
GATEiit

GATE CSE 2022 Q43: Output of printing a[i][0][k] from a 3-D array

Question

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;
}

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 2/3 mark in GATE.
Show answer and explanation

Answer: A (official GATE 2022 final answer key)

Concept used: Each inner brace list initialises one a[i] (a 3×3 block) in row-major order; j stays 0 throughout.

First step: a[i][0][k] is the first row of block i, i.e. the first three numbers of the i-th inner list.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2022 CS question paper and final answer key, organised by IIT Kharagpur. Question paper · Answer key