What is the output of the following C code? Assume that the address of \(x\)…

2015

What is the output of the following C code? Assume that the address of \(x\) is 2000 (in decimal) and an integer requires four bytes of memory.

int main () {
unsigned int x [4] [3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};
printf ("%u, %u, %u", x + 3, *(x + 3), *(x + 2) + 3);
}

  1. A.

    2036, 2036, 2036

  2. B.

    2012, 4, 2204

  3. C.

    2036, 10, 10

  4. D.

    2012, 4, 6

Attempted by 145 students.

Show answer & explanation

Correct answer: A

Key idea: compute addresses using row size and remember that arrays decay to pointers in expressions.

Step-by-step:

  • Each row has 3 integers and each integer is 4 bytes, so one row occupies 3 * 4 = 12 bytes.

  • x + 3 is the address of the fourth row: 2000 + 3 * 12 = 2036.

  • *(x + 3) is the array at that row which decays to a pointer to its first element, so when printed as an unsigned integer it yields the same address 2036.

  • *(x + 2) + 3 starts at the third row: address = 2000 + 2 * 12 = 2024. Adding 3 in pointer arithmetic moves by 3 integers = 3 * 4 = 12 bytes, so 2024 + 12 = 2036.

Final output: 2036, 2036, 2036

Note: Using %u to print pointer values is not portable or strictly correct in C; the question explicitly treats addresses as unsigned numbers for this calculation.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir