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.

KnowledgeGate Team

Exam prep & CS education

Updated 2 Dec 20264 min read
GATE 2023 C Programming Questions: Topics, Traces and Revision Priorities

You may remember a C question's answer and still struggle to explain which rule produced it. The GATE 2023 pair below tests persistent data and separate function calls through two short traces. Distinguishing those rules is more useful than memorising the answer key, especially when a familiar snippet changes slightly.

GATE 2023 C questions: static state and activation trees

Question numbering, marks and keys here follow the official GATE 2023 CS master paper and answer key. In the official GATE archive, select the 2023 Computer Science paper and CS answer key.

Q35 tests static-local state for 1 mark, while Q36 tests activation-tree structure for 2 marks. Together they form a focused pair rather than a full C or Programming and Data Structures survey. Use the wider GATE CS preparation resources to place this focused paper review within your preparation across subjects.

Topic-wise distribution: state retention and function calls

The useful distinction is what you must track while reading each program.

Master question

Primary topic

Format/marks

Skill checked

Q35

Static local variable

NAT, 1

Retain state between calls

Q36

Recursion and activation tree

MCQ, 2

Attach each invocation to its caller

Count Q35 once, even though its static variable sits inside a function. For Q35, your working needs a persistent value; for Q36, it needs separate nodes for separate invocations. A C-looking snippet elsewhere in the paper is not automatically another C-semantics question. Classify by the concept needed to solve it, then choose a trace table or a call tree accordingly. That makes the classification useful for revision.

For the earlier GATE 2015 sweep, which owns pointer parameters, recursion return values and control-flow bookkeeping, see GATE 2015 C Programming Questions: Topic Map and Worked Traces. This 2023 analysis stays with static-local lifetime and activation-tree parentage.

Q35 worked trace: a static variable survives the return

c
#include<stdio.h>
int funcp(){
    static int x = 1;
    x++;
    return x;
}
int main(){
    int x,y;
    x = funcp();
    y = funcp()+x;
    printf("%d\n", (x+y));
    return 0;
}

There are two different variables named x. The one in main receives a return value. The static one belongs to funcp and retains its value between calls, a distinction covered in C storage classes.

On the first call, static x changes from 1 to 2 and returns 2. Therefore, main's x becomes 2. On the second call, static x starts at its retained value 2, increments to 3 and returns 3.

After assignment

Static x

main's x

main's y

x = funcp()

2

2

Uninitialised

y = funcp()+x

3

2

3 + 2 = 5

The printed value is 2 + 5 = 7. Check the GATE 2023 static-local question and solution after doing the trace yourself. The static initialisation happens once; returning from funcp does not reset it.

Q36 worked trace: every call has a parent

Activation tree for main, f2(2), and nested calls, with each invocation attached to its caller.
c
int f1(){ return(1); }
int f3(){ return(5); }
int f2(int X){
    f3();
    if (X==1)
        return f1();
    else
        return (X*f2(X-1));
}
int main(){
    f1();
    f2(2);
    f3();
    return(0);
}

An activation tree gives each invocation its own node. main calls f1(), f2(2) and finally f3(). Here, f1 returns 1 and f3 returns 5. Every f2(X) first calls f3(); at X==1 it returns f1(), otherwise it returns X*f2(X-1).

The invocation order is main, then f1, f2(2), f3, f2(1), f3, f1 and the final f3. These arrows mean next invocation, not parentage. Each leaf returns before its caller resumes.

f2(1) returns 1, so f2(2) returns 2 times 1 = 2. The return value 5 from each f3() call is discarded.

Activation tree with main at the root, calls to f1, f2(2), and f3, and nested f3 and f1 calls under f2.

This tree matches option (a), official key A. The task asks for tree structure; the program prints nothing. Compare your parent edges with the GATE 2023 activation-tree question and solution.

How difficult were these two questions?

Q35 is a short, direct trace once static lifetime is clear. Q36 needs more bookkeeping because the same function name appears in separate invocations. Its challenge is keeping the caller attached to each node while execution moves between functions.

If you obtained 6 for Q35, check whether you reset static x to 1 on the second call: that mistake gives y = 2 + 2 = 4, then 2 + 4 = 6. If Q36 became a flat chain, you confused chronological order with parentage. A repeated function name does not mean a shared activation.

Practice retained state and caller edges

Use this diagnostic sequence:

  • If Q35 resets static x: keep one lifetime ledger for the static variable and a separate value for main's x.

  • If Q36 becomes a flat chain: redraw parent edges from each caller and treat the invocation order as a sequence, not as the tree.

  • If the output becomes 6: recompute the second call from retained static x = 2, then verify y = 5 and the final sum 7.

After the checks, retry both questions without looking at the solutions. If one check still fails, repeat that trace with the relevant ledger rather than adding unrelated practice.

Before moving on, explain why the static variable is initialised only once and assign a caller to every invocation. Then revise scope and lifetime, parameter passing, and arrays and pointers. The C Programming for GATE: A 6-Week Topic-by-Topic Plan gives that work a longer sequence.

The next step after the 2023 paper

Keep three habits from this pair: preserve static state, separate variables that share a name and draw one node per invocation. These habits transfer to fresh questions; a pair cannot guarantee a future topic distribution.

For broader practice, KnowledgeGate's GATE, PSU, Engineering & Technical Exams bank has about 380 C Programming questions across the subject. After completing both traces independently, consider GATE Guidance by Sanchit Sir for structured preparation and practice. Start your next question by identifying exactly what persists and what gets a fresh invocation.