GATE CSE 2022 Q21: Output of a C program using pointers to an int and an array
- Programming and Data Structures
- 1 mark
- MCQ
- −1/3 if wrong
Question
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\n", x, z[0], z[1]);
return 0;
}Try it: multiple choice: exactly one correct option
Wrong answer costs 1/3 mark in GATE.
Show answer and explanation
Answer: D (official GATE 2022 final answer key)
Concept used: Writing through a pointer changes the variable it points to; &z[0] + 1 is the address of z[1].
First step: *p = 10 runs while p points to x; then *(&z[0] + 1) += 3 updates z[1].
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
Source: official GATE 2022 CS question paper and final answer key, organised by IIT Kharagpur. Question paper · Answer key
More Programming and Data Structures PYQs
- 2026 Session 1 · Q23Non-leaf indices in a 1-indexed binary heap with n odd
- 2026 Session 1 · Q24Empty slots after linear-probing inserts with h(x) = (x+7) mod 11
- 2026 Session 1 · Q33Maximum height of a full binary tree with 23 nodes
- 2026 Session 1 · Q34Output of a C function with a shadowed block variable
- 2026 Session 1 · Q39Recursive length of a non-empty singly linked list
- 2026 Session 1 · Q40Third insertion that can never yield a complete BST of 1..15