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.

KnowledgeGate Team

Exam prep & CS education

Updated 28 Nov 20265 min read
GATE 2019 C Programming Questions: Topic Map and Six Worked Traces

Remembering a PYQ's answer does not explain how the program reaches it. In the GATE 2019 C Programming questions, parameter copies, pointer positions, unreachable recursion bases, persistent static state and loop boundaries determine the result. The earlier GATE 2015 C Programming Questions: Topic Map and Worked Traces maps fourteen questions across arrays, functions, control flow and storage classes; the six 2019 traces isolate execution state and output.

Question-skill map for the six traces

The six questions fall into four solving skills: function arguments, arrays and pointers, recursive termination, and loop execution with persistent state.

Main skill

Questions

Count

Function arguments and local variables

Q2937

1

Arrays and pointer expressions

Q2943, Q2972

2

Recursive termination

Q2945

1

Loop execution and persistent state

Q2946, Q2971

2

Total

Six reviewed questions

6

Q2946 also tests static storage, while Q2972 includes iteration. These labels identify the main solving step, not official marks or topic weightage. Likewise, C syntax alone does not make an OS fork() question a C Programming question.

The official archived GATE 2019 CS paper supplies the historical wording. Use the GATE, PSU, Engineering & Technical Exams hub to place C practice in the wider exam route.

Function calls: keep caller and callee variables separate

In Q2937, the GATE 2019 function-call question, jumble computes 2*x+y using its own parameters:

c
int jumble(int x, int y) {
    x = 2*x+y;
    return x;
}

The caller starts with x=2, y=5 and executes two assignments:

  1. y=jumble(y,x) passes (5,2). The return value is 2*5+2=12, so the caller now has (x,y)=(2,12).

  2. x=jumble(y,x) passes (12,2). The return value is 2*12+2=26, leaving (x,y)=(26,12).

Printing the caller's x therefore gives 26. C passes these integers by value: changing a parameter changes the callee's local copy. Parameter names do not identify the caller's variables. Write the argument values before entering each call; do not mentally substitute matching names. There is no recursive call here.

Arrays and pointers: distinguish values from positions

Array and pointer lanes show ip[1] reaching 6 and b's five contributions reaching sum 10.

Q2943, the GATE 2019 array-indexing question, uses:

c
int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5};
int *ip=arr+4;

Indexing starts at zero. Thus ip points to arr[4], whose value is 5. The requested expression is ip[1]=*(ip+1)=arr[5]=6. The output is 6, because the subscript moves one element beyond ip.

Q2972 uses a={2,4,6,8,10}, b=a+4 and sum=0. For i=0 through 4, it adds (*b-i)-*(b-i):

i

*b-i

*(b-i)

Contribution

Running sum

0

10

10

0

0

1

9

8

1

1

2

8

6

2

3

3

7

4

3

6

4

6

2

4

10

The pointer b stays fixed. *b-i subtracts from the value 10; *(b-i) moves backwards by i integer elements before reading. No byte-size assumption is needed.

Despite the source indentation, the loop has no braces, so only the sum statement repeats and printf runs once afterwards, printing 10.

Recursion: prove the base case can be reached

Q2945, the GATE 2019 recursive-termination question, has this control flow:

c
if (n < 0)
    printf("%d", n);
else {
    convert(n/2);
    printf("%d", n%2);
}

The original question asks about any positive integer. Choose 5 only to illustrate the trace: integer division gives 5 → 2 → 1 → 0 → 0 → ....

The base condition is n<0, not n==0. No call reaches a negative argument. At zero, the function calls itself with zero again, so no recursive call returns to its pending print statement.

The derived behaviour is no output and no normal termination; a real system can exhaust stack resources. It does not print binary digits on the way down. Before predicting a recursive output, check both whether the base case is reachable and whether printing occurs before or after the recursive call.

Loops: count every call and test the boundary

Q2946 defines r() with static int num=7 and return num--;, then executes:

c
for (r(); r(); r())
    printf("%d", r());

Post-decrement returns the old value. Static state persists across calls. Read every call in execution order:

Role

Returned value

Initialisation

7

Condition

6

Print

5

Update

4

Condition

3

Print

2

Update

1

Condition, stop

0

The output is 52, without a space. Counting only calls inside printf misses the changes made by loop control.

Q2971 starts with sum=0.0, j=1.0, i=2.0. While i/j>0.0625, it doubles j, adds i/j to sum, then prints.

Execution

Updated j

Added i/j

Sum

1

2

1

1

2

4

0.5

1.5

3

8

0.25

1.75

4

16

0.125

1.875

5

32

0.0625

1.9375

The tested ratios are 2, 1, 0.5, 0.25, 0.125, 0.0625. Equality fails the strict > test, so there are five prints. The condition uses the current j; the addition uses the doubled j.

Across the traces, use a different ledger for each construct: caller and callee rows for Q2937, index and value rows for Q2943 and Q2972, argument sequences for Q2945, call-return values for Q2946, and ratio checkpoints for Q2971. A memorised output fails as soon as one operator or boundary changes.

How difficult were these questions to trace?

Q2945 is the sharpest conceptual trap: zero is not a base case, so the stack never unwinds. Q2971 is a boundary trap because the ratio tested before each body is one step ahead of the ratio added to sum. These distinctions are more useful than a single difficulty label.

Try closed-book predict-the-output practice, then label each miss: parameter binding, index origin, value versus address, unreachable base case, persistent state, or loop boundary. A specific error label tells you what to revise. Official topic weightage requires the exam authority's paper and notification.

Turn the analysis into the next revision session

Use a 45-minute study session:

  • 10 minutes: re-derive the array and pointer traces.

  • 10 minutes: trace function arguments and static state.

  • 10 minutes: check recursion and loop boundaries.

  • 10 minutes: retry missed questions without notes.

  • 5 minutes: record the exact error behind each miss.

Explain each answer before checking it. Extend this session with the six-week C Programming revision plan. If you need structured instruction to support your revision, explore GATE Guidance by Sanchit Sir.