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

You can remember C syntax yet lose a trace when aliases, static variables or unsigned values interact. The eleven GATE CS 2017 questions span Set 1 and Set 2. Their pointer, static-state, unsigned-arithmetic and recursion traces show where careful tracking changes the answer.
What these 2017 questions cover
Each question is assigned to its dominant skill; overlapping ideas remain visible in the worked traces.
Primary topic | Set 1 count | Set 2 count | Total |
|---|---|---|---|
Pointer assignment and allocated memory | 1 | 1 | 2 |
Recursion | 2 | 0 | 2 |
Storage duration and declarations | 1 | 1 | 2 |
Operators and unsigned arithmetic | 1 | 1 | 2 |
Array traversal and strings | 0 | 2 | 2 |
Loop invariant and termination | 0 | 1 | 1 |
Total | 5 | 6 | 11 |
The counts describe this eleven-question sample; they do not estimate full-paper marks or topic weightage.
Check the original papers in IIT Guwahati’s official previous-paper archive. The earlier GATE 2015 C analysis owns the broad 2015 inventory; this page isolates the 2017 values and traces. Pair them with GATE exam courses when you plan revision.
Pointers: a copied value is not an alias
(GATE 2017 Set 2, see the solved page)
void printxy(int x, int y) {
int *ptr;
x=0;
ptr=&x;
y=*ptr;
*ptr=1;
printf("%d, %d", x, y);
}
/* invocation: printxy(1,1) */(a) 0,0
(b) 0,1
(c) 1,0
(d) 1,1
Track (x,y): initially (1,1), after x=0 it is (0,1), after y=*ptr it is (0,0), and after *ptr=1 it is (1,0). Output: 1, 0, option (c). The copy into y does not create an alias.
Recursion: test progress before counting calls
In the Set 1 comparison, both functions initialise local x=0 and end with return val;. Their loops differ:
/* foo */ while(val>0) { x=x+foo(val--); }
/* bar */ while(val>0) { x=x+bar(val-1); }foo(3) passes 3 to its child. The parent decrements before child execution, but every new child still starts at 3. Stack growth is unbounded: the expected outcome is abnormal termination from stack overflow.
bar(3) reaches bar(2), bar(1), then bar(0). Zero returns, but bar(1) never changes its own val; it repeatedly calls bar(0). This is an infinite loop, with at most four active frames. Checking both kinds of progress makes this more demanding than the pointer trace.
Operators and unsigned arithmetic need different traces
For the Set 2 increment question, start with m=10:
Statement |
|
|---|---|
|
|
|
|
|
|
|
|
|
|
Output is 0. These are separate full expressions, so the increments have a defined order.
The Set 1 string-length question needs type reasoning. With s="abc", t="defgh" and unsigned int c=0, evaluate:
int len=((strlen(s)-strlen(t))>c)?strlen(s):strlen(t);Under the question’s unsigned-int model for size_t, 3-5 wraps to UINT_MAX-1, which exceeds zero. The selected length is 3.
The C Programming syllabus areas and preparation order helps place both skills in revision.
Static storage changes every later return value

(GATE 2017 Set 1, see the solved page)
int total(int v) {
static int count = 0;
while(v) {
count += v&1;
v >>= 1;
}
return count;
}
/* main: static int x=0; int i=5;
for(; i>0; i--) x=x+total(i);
printf("%d\n", x); */v&1 extracts the lowest bit; shifting visits the remaining bits. The static count survives each return.
i | Binary | New set bits | Count returned | x after addition |
|---|---|---|---|---|
5 | 101 | 2 | 2 | 2 |
4 | 100 | 1 | 3 | 5 |
3 | 11 | 2 | 5 | 10 |
2 | 10 | 1 | 6 | 16 |
1 | 1 | 1 | 7 | 23 |
Thus x=2+3+5+6+7=23. Resetting count each call would incorrectly give 7. This moderately demanding trace needs separate columns for persistent count and accumulated x.
Arrays, strings and loop invariants reward precise indexing

In Set 2, let char *c="GATECSIT2017"; char *p=c;. Evaluate strlen(c+2[p]-6[p]-1). In ASCII, 2[p]=p[2]='T'=84 and 6[p]=p[6]='I'=73, the offset is 84-73-1=10. Zero-based index 10 starts "17", so the answer is 2.
Another Set 2 question divides x by y using repeated subtraction. All four variables, x, y, q and r, are unsigned int:
while(r>=y) {r=r-y; q=q+1;}Which condition before execution ensures that the loop terminates with x==y*q+r?
(a)
(q==r) && (r==0)(b)
(x>0) && (r==x) && (y>0)(c)
(q==0) && (r==x) && (y>0)(d)
(q==0) && (y>0)
(c) establishes x==y*q+r: initially y*0+x=x. Each iteration preserves it because y*(q+1)+(r-y)=y*q+r. Positive y makes r decrease until r<y.
For example, with x=17,y=5, (q,r) moves (0,17)→(1,12)→(2,7)→(3,2), preserving 17=5q+r. (b) leaves q unspecified: starting at x=r=17,y=5,q=1 ends at q=4,r=2, but 5*4+2=22, not 17. Requiring x>0 is unnecessary; x=0 works. At y=0, the unsigned comparison stays true and subtraction makes no progress.
A trace checklist for the remaining questions
Before choosing an option, label every changing object. For a pointer question, write the pointer value and the pointee in separate columns. For recursion, record the argument passed to the child and the state that survives the return. For unsigned arithmetic, write the type beside each subtraction before deciding whether it can wrap. For an array expression, mark the unit of each pointer step: a row pointer advances by a whole row, while an element pointer advances by one element.
The table also gives a practical order for unworked items. Start with the two pointer and allocation questions, then test the recursive calls while the stack is visible. Finish with the loop and string cases by writing the stopping condition and the index range before evaluating the expression. That sequence turns a topic label into a checkable trace instead of a guess from the answer choices.
Revision session: separate values, lifetime and termination
These questions reward tracking values, lifetime and termination. Separate straightforward assignment traces from persistent-state and recursion problems.
Use one 60-minute session:
10 minutes: declarations and unsigned rules.
20 minutes: two paper traces without a compiler.
15 minutes: recursion and termination.
15 minutes: log errors and retry.
If interrupted, finish the error log next session. Extend the routine with the topic-by-topic C revision plan. For structured guidance, take the next step with GATE Guidance by Sanchit Sir.
Keep learning
GATE 2013 C Programming Questions: Topic Breakdown and Worked Traces
Track one shared variable through recursion, then catch repeated character replacements. Three selected GATE 2013 questions show how to diagnose mistakes with state tables.
GATE 2018 C Programming Questions: Topic Breakdown and Solving Lessons
Remembering an output is not enough. Trace four GATE 2018 C questions to see which variables change, when calls count, and where loops stop.
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.
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.





