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.

KnowledgeGate Team

Exam prep & CS education

Updated 28 Nov 20265 min read
GATE 2020 C Programming Questions: Topic Split and Three Worked Traces

Pointer arithmetic and recursive state are easy to misread when a final value hides the intermediate steps. The GATE 2020 set contains three NAT questions: an array expression returns 19, a static-recursion program returns 55, and a bit loop returns 81. They form a sample, not an official subject-wise marks allocation or an exhaustive inventory of C questions.

GATE 2020 C questions: source and scope

The previous-papers page on IIT Bombay's GATE 2021 website lists the GATE 2020 Computer Science question paper and answer key. The archive supplies the paper and key; each question's main solving skill determines its topic label.

These three GATE-tagged C questions are numerical answer type (NAT), so there are no options to eliminate. Derive the output or return value. For broader study planning, use the GATE preparation resources.

Earlier GATE C topic maps serve broader inventories. The 2015 C topic map covers fourteen questions across five skill groups; the 2020 set isolates three NAT questions and derives 19, 55 and 81.

Topic-wise split of the three verified questions

Each row assigns one primary teaching topic, so the total remains three.

Primary teaching topic

Identifying expression

Count

Skill

Arrays and pointers

*(*(a+**a+2)+3)

1

Row-versus-element stepping

Recursion and static storage

fun2(5)

1

Persistent state

Loops and binary representation

pp(3,4)

1

Repeated squaring

Total

3

The course taxonomy places pp under Array Basics. Here, its main solving operation gives it the loops and binary representation label. An array stores the bits, but tracking those bits through repeated squaring explains the answer. Topic overlap does not create an extra question.

Arrays and pointers: why the expression prints 19

Array-pointer trace highlights row 3, column 3, where a[3][3] equals 19.

Find the output of this array expression:

c
int a[4][5] = {{1,2,3,4,5},
               {6,7,8,9,10},
               {11,12,13,14,15},
               {16,17,18,19,20}};
printf("%d\n", *(*(a+**a+2)+3));

(GATE 2020, array-pointer solved trace)

Start at the innermost value, then track the pointer's unit:

  1. **a = a[0][0] = 1.

  2. a + **a + 2 = a + 1 + 2 = a + 3, selecting row index 3.

  3. *(a + 3) gives the fourth row, which decays to a pointer to its first integer in this addition.

  4. *(a + 3) + 3 points to column index 3. The final dereference reads a[3][3] = 19.

The output is 19. In a+1, one step crosses a row of five integers. After selecting the row, +3 crosses three integers. No assumed byte width is needed. The trap is treating both additions as single-integer moves; review the pointer arithmetic rules if that distinction is unclear.

A 4-by-5 integer grid highlights a[0][0]=1, row 3, column 3, and the selected value a[3][3]=19.

Recursion and static variables: tracing fun2(5) to 55

Find fun2(5) in a fresh execution:

c
int fun1(int n) {
    static int i = 0;
    if (n > 0) {
        ++i;
        fun1(n-1);
    }
    return(i);
}
int fun2(int n) {
    static int i = 0;
    if (n > 0) {
        i = i + fun1(n);
        fun2(n-1);
    }
    return(i);
}

(GATE 2020, static-variable recursion solution)

There are two distinct static objects, initially zero. Each persists across calls to its own function. fun1(n) increments its static n times; it does not restart at zero when called again.

n

fun1(n) returned

fun2 static i after addition

5

0+5 = 5

0+5 = 5

4

5+4 = 9

5+9 = 14

3

9+3 = 12

14+12 = 26

2

12+2 = 14

26+14 = 40

1

14+1 = 15

40+15 = 55

At n=0, fun2 returns 55. Every unwinding frame also reads the same static and returns 55, even though the recursive return value is ignored. The two variables share a name, not storage. Since fun1 never changes fun2's i, operand evaluation order in i + fun1(n) does not change this result.

Binary representation and loops: why pp(3,4) returns 81

Find the value returned by pp(3,4):

c
int tob(int b, int* arr) {
    int i;
    for (i=0; b>0; i++) {
        if (b%2) arr[i]=1;
        else arr[i]=0;
        b=b/2;
    }
    return(i);
}
int pp(int a, int b) {
    int arr[20];
    int i, tot=1, ex, len;
    ex=a;
    len=tob(b,arr);
    for (i=0; i<len; i++) {
        if (arr[i]==1)
            tot=tot*ex;
        ex=ex*ex;
    }
    return(tot);
}

(GATE 2020, repeated-squaring solved trace)

Integer division takes b through 4 to 2 to 1 to 0. The remainders are 0,0,1, so arr stores the bits least significant first, and len=3. This reverses the usual written order of binary 100.

i

Bit

ex before

tot after

ex after

0

0

3

1

3x3 = 9

1

0

9

1

9x9 = 81

2

1

81

1x81 = 81

81x81 = 6561

Only the last stored bit triggers multiplication into tot. The final squaring still executes, but the returned total remains 81, matching 3^4. Trace the two functions together instead of guessing from their names.

Difficulty comes from state tracking, not code length

The main risk is state tracking: the array expression is short once row types are recognised, static recursion carries greater bookkeeping risk, and pp requires connecting two functions while preserving bit order.

These traces use different state models: pointer arithmetic changes the object selected, static storage preserves state across calls, and the binary loop stores exponent bits least-significant first. A correct trace records the state after each operation, then checks the final value against the return path.

Close the tables and reproduce 19, 55 and 81. For each miss, record the cause: wrong pointer unit, reset static state, or reversed bit order. Repair that specific step before attempting another question. Recalling the final answer without a valid trace is not mastery.

If your errors span several concepts, the six-week C revision plan helps organise the next round of practice.

Turn the three traces into your next practice session

Use a two-pass 25-minute drill: spend 5 minutes writing a state column for each trace, 15 minutes re-deriving 19, 55 and 81 without notes, and 5 minutes classifying the first wrong transition. The next day, rebuild all three traces on blank paper and explain each state change aloud.

Prioritise the concept behind your first incorrect step. If you need to rebuild those foundations before more PYQs, use the C Language course for concept repair.