GateAI
Programming in C

GATE CSE 2022 · Q21

MCQ1 markEasy

Time

What is printed by the following ANSI C program?#include<stdio.h> int main(int argc, char *argv[]) { int x = 1, z[2] = {10, 11}; int *p = NULL; p = &x; *p = 10; p = &z[1]; *(&z[0] + 1) += 3; printf("%d, %d, %d ", x, z[0], z[1]); return 0; }

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) 10, 10, 14

Programming in C

Let us trace the execution of the program step-by-step:

  1. Initialization:

    • int x = 1; initializes variable x to 1.

    • z[2] = {10, 11}; initializes z[0] = 10 and z[1] = 11.

    • int *p = NULL; initializes pointer p to NULL.

  2. Pointer operations on x:

    • p = &x; sets pointer p to store the address of x.

    • *p = 10; dereferences p and assigns 10 to x. Thus, x becomes 10.

  3. Pointer arithmetic on array z:

    • p = &z[1]; updates p to point to z[1].

    • *(&z[0] + 1) += 3;:

      • &z[0] is the address of z[0].

      • Adding 1 advances the pointer by sizeof(int) bytes, pointing to &z[1].

      • Dereferencing *(&z[0] + 1) accesses z[1].

      • += 3 increases the value of z[1] from 11 to 11+3=1411 + 3 = 14.

    • z[0] remains unchanged as 10.

  4. Output:

    • `printf("%d, %d, %d

", x, z[0], z[1]); prints 10, 10, 14`.

Hence, the correct option is (D).

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 Q21 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. 20 of them are 1-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 · Q21 · MCQ

What is printed by the following ANSI C program? #include int main(int argc, char *argv[]) { int x = 1, z[2] = {10, 11}; int *p = NULL; p = &x; *p = 10; p = &z[1]; *(&z[0] + 1) += 3; printf("%d, %d, %d ", x, z[0], z[1]); return 0; }

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.