GATE 2014 C Programming Questions: Topic Analysis and Worked Traces
Trace seven selected GATE 2014 C questions to understand pointer input, double swaps, search boundaries and integer arithmetic. Use the mistakes to guide a focused revision session.
KnowledgeGate Team
Exam prep & CS education

Tracing C code means tracking what each statement changes. Seven GATE CS 2014 questions illustrate pointer input, shifts, static recursion, unsigned arithmetic, matrix swaps, search bounds and interval sums. The table groups each question by its dominant skill; the worked traces derive the outputs and state changes. It is a revision map, not an official year-wide distribution.
GATE 2014 C question map by skill
Primary skill | Sample items | Tagged set and identifying question |
|---|---|---|
Pointer input | 1 | Set 1, scanf through pi |
Array and matrix reasoning | 3 | Set 1, MyX; Set 3, matrix swaps and ProcessArray |
Static state and recursion | 1 | Set 2, f with static i=50 |
Integer arithmetic and overflow | 1 | Set 2, unsigned n choose 3 |
Bit shifts and loop termination | 1 | Set 2, func(435) |
The counts total seven, with each item assigned once. Array algorithms overlap with Algorithms; the combination question belongs under arithmetic because that is the reasoning it tests.
Use GATE, PSU, Engineering & Technical Exams for the wider exam route. The C Programming for GATE: Tested Areas and Prep Order handles syllabus scope and weightage context; these seven GATE 2014 traces handle their worked values and control flow. The GATE 2015 C Programming Questions: Topic Map and Worked Traces map publishes earlier and owns the 2015 inventory, while these traces stay with 2014 values and control flow. For historical papers, use IIT Roorkee's official previous-paper archive.
Pointer input: follow the address, then the value

(GATE 2014 Set 1, pointer-input solved page)
The operative statements are:
int i;
int *pi = &i;
scanf("%d", pi);
printf("%d\n", i+5);Assume successful conversion with input 7. Before input, pi holds the address of i. scanf stores 7 in i; then i+5 = 7+5 = 12, so the output is 12.
The pointer still holds an address, not 7. Passing &pi would supply the address of the pointer itself. The distinction is address versus value. For pointer arithmetic rules and worked examples, read Pointer Arithmetic in C: Rules and Worked Examples.
Right shifts: count iterations, not set bits

(GATE 2014 Set 2, right-shift solved page)
int func(int num) {
int count=0;
while(num) {
count++;
num >>= 1;
}
return count;
}For the question's call func(435):
num before shift | count after increment |
|---|---|
435 | 1 |
217 | 2 |
108 | 3 |
54 | 4 |
27 | 5 |
13 | 6 |
6 | 7 |
3 | 8 |
1 | 9 |
The final shift produces zero; the return value is 9. Check independently: 256 <= 435 < 512, so 435 needs nine binary digits. Its binary representation, 110110011, has six set bits. The loop counts digits, not ones.
Static recursion and finite integer arithmetic
In Set 2's recursive function, the decisive fragment is:
static int i=50;
if(i==j) {
printf("something");
k=f(i);
return 0;
} else return 0;The call f(49) returns zero without printing. The call f(50) calls f(50) again. Since i never changes, there is no normal termination; the return after recursion is never reached.
The unsigned combination question compares these expressions:
(a)
p = n*(n-1)*(n-2)/6;(b)
p = n*(n-1)/2*(n-2)/3;(c)
p = n*(n-1)/3*(n-2)/2;(d)
p = n*(n-1)*(n-2)/6.0;
Expression (b) preserves the intended integer result. Multiplication and division group left to right. Two consecutive integers have an even product, so its division by 2 is exact. Multiplying by n-2 then gives three times the combination value, exactly divisible by 3, provided intermediates fit.
For n=5, the true value is 5*4*3/6 = 10:
Expression | Successive values |
|---|---|
(b) | 20, 10, 30, 10 |
(c) | 20, 6, 18, 9 |
Option (c) truncates 20/3 to 6. Option (a) forms six times the answer before dividing; (b) reduces overflow risk but still requires representable intermediates and result. Option (d) cannot undo unsigned-product overflow and also introduces floating-point rounding risk.
Array code: identify the invariant before naming the algorithm
(GATE 2014 Set 3, matrix-swap solved page)
The matrix pseudocode visits every ordered pair (i,j) with C=100:
Temp = A[i][j] + C
A[i][j] = A[j][i]
A[j][i] = Temp - CFor matrix [[1,2],[3,4]], using one-based positions:
Visit | Temp | Matrix afterwards |
|---|---|---|
(1,1) | 101 | [[1,2],[3,4]] |
(1,2) | 102 | [[1,3],[2,4]] |
(2,1) | 102 | [[1,2],[3,4]] |
(2,2) | 104 | [[1,2],[3,4]] |
Each off-diagonal pair swaps twice. The result is the original matrix, not its transpose.
Set 3's ProcessArray starts i=0,j=n-1, computes k=(i+j)/2, and uses two independent tests:
if(x<=listA[k]) j=k-1;
if(listA[k]<=x) i=k+1;For sorted [2,4,6,8,10], searching for 8 visits (i,j,k)=(0,4,2), then (3,4,3). Equality sets both j=2 and i=4; the loop stops and returns index 3. Searching for 7 follows the same midpoints, but the comparison against 8 sets only j=2, ending with -1. Both tests executing on equality preserves the result.
Set 1's MyX first accumulates the whole-array sum into Y, then compares every nonempty contiguous interval sum against it. For [-2,3,-1], initial Y=0; interval sums are -2,1,0,3,2,-1, so Y moves from 0 to 1 to 3.
For [-2,-3], initial Y=-5; sums -2,-5,-3 give -2, not zero. The invariant is the largest nonempty contiguous sum examined, including the initial whole array.
Turn the difficulty read into a revision session
Pointer input and positive shifts are direct; static recursion tests unchanged state. Double swaps, search boundaries and arithmetic need careful tracing.
A 45-minute revision block:
10 minutes: pointer and shift traces.
15 minutes: matrix, search and interval traces.
10 minutes: recursion and arithmetic.
10 minutes: error log and closed-notes retry.
Record the missed invariant, not just the answer. A seven-question sample cannot establish future weightage; use the official notification for the current paper.
The short version and next step
Record state, respect loop bounds and distinguish mathematical arithmetic from fixed-width C arithmetic. Redo one missed trace with new input before moving to another year. Use GATE Guidance by Sanchit Sir for broader structured preparation.
Keep learning
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.
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 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.





