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.
KnowledgeGate Team
Exam prep & CS education

Remembering C syntax does not guarantee that you can track what changes during a function call. Six selected GATE 2016 C questions, four from Set 1 and two from Set 2, expose that distinction through three worked traces and a revision order.
Where can you find the original papers?
IIT Roorkee's official previous-paper archive lists a bulk archive for 2007 to 2024 for original-paper checking. Open the relevant set before attempting a question, and keep its declarations beside the code. In C, a single * changes what an expression means: p is a pointer value, while *p accesses the object it points to. Copy the initial values and the exact expression being printed before starting your trace. This separates a reading mistake from a tracing mistake when you compare your answer.
Use this analysis alongside GATE, PSU, Engineering & Technical Exams when organising wider preparation.
Topic-wise distribution
Each question appears once in these skill buckets. Recursion can involve arrays without earning a second count.
Skill bucket | Question count |
|---|---|
Pointer parameters and caller state | 2 |
Function-argument types | 1 |
Array loop invariant | 1 |
Recursion and persistent state | 2 |
Practise state tracing, argument types and loop termination together.
Pointer arguments: changing a pointee versus swapping local pointers
The GATE 2016 Set 2 pointer-parameter question uses this function:
void f(int *p, int m) {
m = m + 5;
*p = *p + m;
return;
}The caller starts with int i=5, j=10;, calls f(&i,j), then prints i+j.
(GATE 2016 Set 2, see the solved trace)
On entry,
ppoints toi; localm=10.m=10+5=15changes only the parameter.*p=5+15=20changes caller variablei.Caller
jremains 10, soi+j=20+10=30.
C passes both arguments by value. The copied pointer still designates caller storage.
The earlier GATE 2015 C Programming Questions: Topic Map and Worked Traces owns value-parameter swaps and caller updates; this 2016 set isolates pointer reassignment, shared static storage and array invariants.
Contrast the GATE 2016 Set 1 pointer-swap question: mystery executes only temp=ptrb; ptrb=ptra; ptra=temp;. Start with a=2016,b=0,c=4,d=42 and follow the addresses separately from the stored integers:
In
mystery(&a,&b), localptrapoints toaand localptrbpoints tob.temp=ptrbsaves the address ofb. It does not copy the integer 0 intoa.ptrb=ptramakesptrbpoint toa;ptra=tempmakesptrapoint tob. Neither statement assigns through a pointer, soa=2016andb=0remain unchanged.Back in the caller,
a<cis2016<4, false. Therefore,mystery(&c,&a)is skipped.The final
mystery(&a,&d)swaps another pair of local pointer values. Again no pointee changes, so the output is 2016.
To exchange the caller's integers, the assignments would need to write to the pointed-to objects. Merely redirecting local pointers cannot perform that exchange.
Draw the distinction using Pointers in C for GATE: Memory Diagrams and Output Traces.
Static storage in recursion: one d, three n values

For the GATE 2016 Set 1 static-storage question, start with count(3):
void count (int n) {
static int d=1;
printf ("%d",n);
printf ("%d",d);
d++;
if (n>1) count (n-1);
printf ("%d",d);
}(GATE 2016 Set 1, see the solved trace)
The entry pairs (n,d) are (3,1), (2,2) and (1,3). Their increments move d from 1 to 2, then 3, then 4. Each call has its own n, but all calls share the single static d; its initialiser does not run again on recursive entry.
Unwinding prints 4 three times. Joining the entry prints 31, 22, 13 and return prints 444 gives 312213444, with no spaces.

Array questions: trace the recurrence and preserve the invariant
The GATE 2016 Set 2 recursive-array function returns 0 for n<=1; otherwise it returns max(f(p+1,n-1),p[0]-p[1]). For {3,5,2,6,4} and n=5, adjacent differences are 3-5=-2, 5-2=3, 2-6=-4, 6-4=2.
(GATE 2016 Set 2, see the solved trace)
Unwind from 0: max(0,2)=2, max(2,-4)=2, max(2,3)=3, max(3,-2)=3. Answer: 3, the largest adjacent drop with a zero floor, not the array maximum 6 or an unrestricted pairwise difference.
The GATE 2016 Set 1 array-loop question starts a=0,b=n-1, discards the smaller endpoint and returns p[a]. Its guard options are:
(a)
a != n(b)
b != 0(c)
b > (a + 1)(d)
b != a
Answer (d), b != a, leaves one candidate. A maximum survives each discard. Option (c) stops too early: {3,5} returns 3 without entering the loop.
Try the loop on another array: {3,5,2,6,4} gives endpoint pairs (0,4)→(1,4)→(1,3)→(2,3)→(3,3), returning p[3]=6. The comparisons are 3<=4 (true), 5<=4 (false), 5<=6 (true) and 2<=6 (true). Each step shrinks the interval by one. The surviving interval still contains a maximum because the discarded endpoint has a remaining endpoint at least as large. For n=1, zero iterations correctly return p[0].
Difficulty comes from the state you forget to track
Pointer copies invite misreading, static recursion requires call order, and the array loop requires an invariant. Before evaluating an expression, mark which variables belong to the caller, which belong to one call and which persist across calls. This small habit makes each update visible and prevents an otherwise correct calculation from using the wrong value.
The GATE 2016 Set 1 function-argument question gives void f(int,short) and int i=100; short s=12; short *p=&s;:
(a)
f(s,*s)(b)
i = f(i,s)(c)
f(i,*s)(d)
f(i,*p)
Answer (d) matches the prototype: i supplies an int, and dereferencing p supplies the short value stored in s.
Option (a) fails because
*sapplies indirection to ashort, although passingsas the first argument would allow conversion toint.Option (b) fails because
freturnsvoid, so there is no result to assign toi.Option (c) fails because its second argument again dereferences
s, which holds an integer, not an address.
Strengthen prerequisites with C Programming for GATE: A 6-Week Topic-by-Topic Plan.
GATE 2016 C revision: three ledgers, one timed pass
Use one 45-minute block to reproduce the three state models:
10 minutes: redo pointer-state traces.
15 minutes: redraw static-recursion and adjacent-difference traces.
10 minutes: prove array-loop termination, including
n=1.10 minutes: log errors and retry without notes.
For a broader sequence, use GATE Guidance by Sanchit Sir. Before checking an answer, write the static d ledger and the endpoint pairs for {3,5,2,6,4}; log which state you lost.
Keep learning
GATE 2019 C Programming Questions: Topic Map and Six Worked Traces
Remembering an output is easier than explaining it. Trace six GATE 2019 C Programming questions, identify the exact execution traps, and use your mistakes to plan revision.
GATE 2015 C Programming Questions: Topic Map and Worked Traces
Knowing a C rule is only the start. Trace pointer updates, recursion and persistent state in GATE 2015 questions, then use the topic map to plan revision.
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 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.





