GateAI

GATE CSE Programming and Data Structures (PDS) PYQs

In GATE CS, Programming in C is tested extensively through rigorous code tracing, pointer mechanics, and fundamental semantics rather than high-level syntax tri… Read the guide

Topics
9
Questions
163
Marks / paper
9.5
Asked
since 2011

These are the 163 GATE CSE Programming and Data Structures PYQs (since 2011), grouped topic-wise with solutions. See all GATE CSE PYQs or GATE CSE question papers by year.

Topics

Open a topic to browse its questions, or practice it as a timed test.

By year

Jump to the first question from each year’s paper.

What GATE tests in Programming and Data Structures

Concepts, patterns, formulas and traps distilled from past papers.

In GATE CS, Programming in C is tested extensively through rigorous code tracing, pointer mechanics, and fundamental semantics rather than high-level syntax trivia. GATE tests Recursion primarily through direct execution tracing of recursive C code snippets, stack-unwinding behavior (pre-order vs. Binary Search Trees (BSTs) in GATE CS test a balance of traversal mechanics, structural properties, worst-case vs.

Core concepts

  • Pointer arithmetic and scale factors based on base type
  • Multidimensional array decaying into pointers (pointer to array vs array of pointers)
  • Storage classes (auto, register, static, extern) and lifetime vs scope
  • Pre-increment vs post-increment evaluation and sequence point rules
  • Short-circuit evaluation of logical AND (&&) and logical OR (||)
  • Pass-by-value vs pass-by-reference/pointer mechanics
  • Recursive call stack tracking with local vs static state retention
  • Dynamic memory management (malloc, free, memory leaks, dangling pointers)
  • String literals, ASCII arithmetic, character pointers, and null termination ('\0')
  • Bitwise operators (&, |, , >) and binary number manipulation
  • Switch-case fall-through behavior without break statements
  • Recursive function execution and call stack reduction

How questions show up

  • Pointer Arithmetic and Multidimensional Array Indexing

    Commonmixed2 marks2026, 2025, 2024, 2022

    Evaluating complex pointer expressions involving 1D/2D/3D arrays, array decaying, pointer subtraction, array subscript commutativity (i[p]≡p[i]i[p] \equiv p[i]), and double dereferencing (∗(∗(a+i)+j)*(*(a+i)+j)).

  • Storage Classes, Variable Scope, and Shadowing

    CommonNAT2 marks2026, 2023, 2020, 2019

    Tracing code containing static local variables retaining state across multiple recursive or iterative function calls, global vs local variable shadowing, and lifetime vs scope distinctions.

  • Parameter Passing and Pointer Swapping Idioms

    Commonmixed1 marks2026, 2025, 2024, 2019

    Testing the distinction between pass-by-value and pass-by-reference using pointers, including classic traps where pointer formal parameters are reassigned locally without dereferencing.

  • Short-Circuit Evaluation, Precedence, and Side Effects

    Commonmixed1 marks2024, 2022, 2021, 2017

    Evaluating expressions involving logical operators (&&, ||) where side-effects like pre/post increment (++i, i++) or assignment are skipped due to short-circuiting, or custom operator precedence tables.

  • Loop Invariants, Algorithm Semantics, and Verification

    OccasionalMCQ2 marks2025, 2024, 2017, 2016

    Formulating correct pre/post-conditions, identifying loop invariants (e.g., division by repeated subtraction, binary exponentiation), or filling missing loop termination/update guards.

  • String Manipulation and Null Termination Pitfalls

    Occasionalmixed1 marks2025, 2024, 2017, 2015

    Tracing pointer-based string copies or scans that miss copying the null terminator '\0', unsigned size_t differences producing underflow, or ASCII arithmetic offsets.

High-yield formulas

Pointer Subtraction

p2−p1=Address(p2)−Address(p1)sizeof(∗p1)p_2 - p_1 = \frac{\text{Address}(p_2) - \text{Address}(p_1)}{\text{sizeof}(*p_1)}

Used when computing the numerical result of subtracting two pointers pointing to elements of the same array.

2D Array Element Address Calculation

Address(A[i][j])=Base(A)+(i×N+j)×sizeof(type)\text{Address}(A[i][j]) = \text{Base}(A) + (i \times N + j) \times \text{sizeof}(\text{type})

Used for mapping multi-dimensional array indices to flat memory offsets in row-major layout.

Array Subscript Equivalence

A[i]≡∗(A+i)≡∗(i+A)≡i[A]A[i] \equiv *(A + i) \equiv *(i + A) \equiv i[A]

Used to resolve commutative and unorthodox array indexing expressions in C snippets.

Cyclomatic Complexity

V(G)=P+1V(G) = P + 1

Used to calculate McCabe's cyclomatic complexity where PP is the count of predicate/decision conditions in the control flow.

Integer Division Loop Invariant

x=q⋅y+r∧0≤r<yx = q \cdot y + r \quad \wedge \quad 0 \le r < y

Used to verify formal loop invariants in repeated subtraction integer division routines.

Euclidean Subtraction GCD

gcd⁡(x,y)={xif x=ygcd⁡(x−y,y)if x>ygcd⁡(x,y−x)if y>x\gcd(x, y) = \begin{cases} x & \text{if } x = y \\ \gcd(x - y, y) & \text{if } x > y \\ \gcd(x, y - x) & \text{if } y > x \end{cases}

Used when analyzing recursive functions that reduce two numbers by repeated subtraction until equality or 1 is reached.

Total Invocations Recurrence

T(n)=1+∑iT(gi(n))T(n) = 1 + \sum_{i} T(g_i(n))

Used to count the total number of function activations including base cases (e.g., T(n)=1+T(n−1)+T(n−3)T(n) = 1 + T(n-1) + T(n-3)).

Digit Sum in Base $r$

S(n,r)=(n mod r)+S(⌊n/r⌋,r)S(n, r) = (n \bmod r) + S(\lfloor n/r \rfloor, r)

Used when recursive functions peel off least significant digits/bits via modulo and integer division.

Examiner traps in Programming and Data Structures

  • Assuming pointer subtraction returns byte difference rather than the number of typed elements.
  • Forgetting switch-case fall-through when break statements are omitted.
  • Evaluating the right operand of && or || when the left operand already determines the result (short-circuit skipping side-effects like i++).
  • Confusing (*p)++ (incrementing the dereferenced value) with *p++ (dereferencing current address then advancing pointer).
  • Forgetting that static local variables in recursive functions retain cumulative updates across all activation records.
  • Overlooking missing null terminators ('\0') in manual string copying loops, causing trailing characters to persist in memory.
  • Failing to account for unsigned arithmetic wrap-around when subtracting unsigned types like sizet from strlen().
  • Thinking a function that takes pointer parameters swaps them in main when the function swaps pointer values locally instead of dereferenced targets.

Paper trends

  • Shift towards Numerical Answer Type (NAT) questions requiring exact printed output calculations rather than multiple-choice guessing.

    2026, 2025, 2023, 2021, 2020, 2019, 2018, 2017, 2015

  • Introduction of non-standard operator precedence tables where candidates must compute expression values based on customized grammar rules rather than default C precedence.

    2024

  • Inclusion of Multi-Select Questions (MSQ) examining algorithmic invariants, asymptotic function bounds, and string pointer validity across multiple scenarios.

    2024

  • Increased focus on subtle C standard specifications such as unsigned arithmetic wrap-around with strlen(), uninitialized struct next pointer dereferencing, and block-scope variable shadowing.

    2026, 2025, 2024, 2021, 2017