GateAI
Programming in C

GATE CSE 2015 Set 1 · Q35

MCQ2 marksMedium

Time

What is the output of the following C code? Assume that the address of xx 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); }

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) 2036, 2036, 2036

Programming in C

Given that x is a 2D array of type unsigned int[4][3] and the base address of x is 20002000. Each row contains 3 integers, taking 3×4=123 \times 4 = 12 bytes.

  1. Evaluating x + 3:

    • x has type unsigned int (*)[3] (pointer to an array of 3 integers).

    • x + 3 points to the 4th row (index 3).

    • Address =2000+3×sizeof(unsigned int[3])=2000+3×12=2036= 2000 + 3 \times \text{sizeof}(\text{unsigned int}[3]) = 2000 + 3 \times 12 = 2036.

  2. **Evaluating *(x + 3):**

    • *(x + 3) is the 4th row x[3], which decays to a pointer of type unsigned int * pointing to its first element x[3][0].

    • Its address value is the same as the start of the 4th row, which is 20362036.

  3. **Evaluating *(x + 2) + 3:**

    • *(x + 2) is the 3rd row x[2], decaying to an unsigned int * pointing to x[2][0].

    • Base address of row 2 =2000+2×12=2024= 2000 + 2 \times 12 = 2024.

    • *(x + 2) + 3 performs pointer arithmetic on unsigned int *, which adds 3×sizeof(unsigned int)=3×4=123 \times \text{sizeof}(\text{unsigned int}) = 3 \times 4 = 12 bytes.

    • Address =2024+12=2036= 2024 + 12 = 2036.

Therefore, printf("%u, %u, %u", ...) outputs 2036, 2036, 2036.

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 Q35 of the GATE CSE 2015 Set 1 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 2015 Set 1 has 4.

How GATE tests Programming in C

More from GATE CSE 2015 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2015 Set 1 · Q35 · MCQ

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

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.