GATE 2022 C Programming Questions: Topic Split and Output Traces
Trace the three C program-output questions from GATE CS 2022. See which objects change, which array index stays fixed, and why character output differs from the calculated codes.
KnowledgeGate Team
Exam prep & CS education

Remembering an answer does not help when the code changes. These three GATE 2022 C Programming questions separate three useful skills: tracking pointer state, following array indices and evaluating character operations. This is a historical snapshot, not a prediction of the next paper.
GATE 2022 C questions: scope and source
The official GATE 2022 CS paper contains three ANSI C program-output questions: Q21, Q43 and Q44. Q15 on linked-list reversal and Q16 on hashing contain no C code, so they remain data-structure questions here.
Question numbers and marks come from the official paper. The grouping below uses each question's main execution skill, so overlapping ideas are not counted twice. For a related year-specific comparison, the GATE 2016 C Programming Questions: Topic Map and Worked Traces follows pointer-parameter and static-recursion traces; GATE 2022's three program-output questions emphasise 3D indexing and ASCII conversion. For wider study, explore the GATE, PSU and Engineering exam resources.
Topic-wise distribution: three questions, five marks
Primary skill | Official question | Format | Marks | Main trap |
|---|---|---|---|---|
Pointer assignment and array-pointer access | Q21 | MCQ | 1 | Confusing pointer reassignment with an object write |
Multidimensional arrays and loop indices | Q43 | MCQ | 2 | Assuming j changes |
Bitwise operators and ASCII | Q44 | MCQ | 2 | Printing codes instead of characters |
The total is 1 + 2 + 2 = 5 marks, with one question per primary topic. Q21 and Q43 also form an array/pointer-related pair worth 1 + 2 = 3 marks, so that overlapping grouping is reported separately. Record object writes, mark changing indices and check the output format.
Record object writes, mark changing indices and check the output format.
Q21: track the object a pointer changes
(GATE 2022, Q21, see the solved page)
Trace this code:
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]);Track targets and values separately:
After statement | p points to | x | z[0] | z[1] |
|---|---|---|---|---|
Initialisation | Nothing, NULL | 1 | 10 | 11 |
p = &x | x | 1 | 10 | 11 |
*p = 10 | x | 10 | 10 | 11 |
p = &z[1] | z[1] | 10 | 10 | 11 |
*(&z[0] + 1) += 3 | z[1] | 10 | 10 | 14 |
Reassigning p does not undo the earlier write to x. &z[0] + 1 points to z[1], giving 11 + 3 = 14. Pointer arithmetic advances by elements, not an assumed single byte.
The output is 10, 10, 14, option (d). Option (b) forgets the write to x; option (c) changes the wrong array element. A state table makes this straightforward. Use the pointer arithmetic rules for more practice.
Q43: a three-dimensional array does not imply three moving indices

(GATE 2022, Q43, see the solved page)
a[3][3][3] contains 1 through 27 in three consecutive nine-element blocks. The loop is:
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");
}Only i and k change. j stays zero, and k restarts at zero for every block. Therefore, the program prints the first row of each block:
i = 0:1 2 3i = 1:10 11 12i = 2:19 20 21
These separate lines match option (a). Advancing i moves nine elements; advancing j would move three, but never happens.
The zero-based element offset is 9i + 3j + k. Here, the stored value is offset + 1. At a[2][0][2], the offset is 9 x 2 + 3 x 0 + 2 = 20, giving 21. This needs moderate bookkeeping.

Q44: perform bit operations before converting back to characters
(GATE 2022, Q44, see the solved page)
Use the ASCII encoding supplied in this question:
Characters | ASCII values |
|---|---|
A, B, C, ..., Z | 65, 66, 67, ..., 90 |
a, b, c, ..., z | 97, 98, 99, ..., 122 |
*, +, - | 42, 43, 45 |
char a = 'P';
char b = 'x';
char c = (a & b) + '*';
char d = (a | b) - '-';
char e = (a ^ b) + '+';
printf("%c %c %c\n", c, d, e);P is 65 + 15 = 80, or 01010000; x is 97 + 23 = 120, or 01111000. Apply each operation before the character constant:
Operation | Binary result | Decimal | Final calculation |
|---|---|---|---|
AND | 01010000 | 80 | c = 80 + 42 = 122 |
OR | 01111000 | 120 | d = 120 - 45 = 75 |
XOR | 00101000 | 40 | e = 40 + 43 = 83 |
Now convert back: 122 is z, 75 = 65 + 10 is K, and 83 = 65 + 18 is S. Since %c prints characters, the output is z K S, option (a).
Bitwise & operates on corresponding bits; logical && tests truth values. %c and %d request different representations. Difficulty is moderate: binary calculation and character conversion need separate passes.
C programming tracing mistakes to fix
These questions test exact execution state more than lengthy coding. Turn each mistake into an error-log entry:
"Forgot x changed": list every dereference write.
"Incremented j mentally": mark only actual loop variables.
"Answered 122 75 83": read the
printfspecifier last.
Explain your trace instead of memorising an option. Redo any faulty step. Recursion and strings still need revision even though they are absent from this set.
C programming revision session: 30 focused minutes
Try this 30-minute exercise: 10 minutes attempting the questions without answers, 10 checking the traces and 10 redoing the exact steps that caused errors. Carry unfinished work forward.
Continue with the topic-by-topic C preparation plan. For guidance, explore GATE Guidance by Sanchit Sir.
Can you explain the changed object, fixed index and output format without recalling the option letter?
Keep learning
GATE 2020 C Programming Questions: Topic Split and Three Worked Traces
Trace three GATE 2020 C questions to 19, 55 and 81. Learn where pointer units, persistent static variables and bit order change the answer, then use the traces to guide revision.
GATE 2023 C Programming Questions: Topics, Traces and Revision Priorities
Remembering an answer is not enough. Trace Q35 and Q36 from GATE 2023 CS to understand static state, separate function invocations and the revision habits each question demands.
GATE 2017 C Programming Questions: Topic Breakdown and Worked Traces
Trace the values that decide the answer: copied pointer values, persistent static counts and recursive calls that never progress. This selected 2017 question set turns those mistakes into a focused revision session.
GATE 2016 C Programming Questions: Topic Map and Worked Traces
Trace caller state, shared static storage and array recurrences in selected GATE 2016 questions. Use the worked answers to identify what to practise next.





