Match the following:
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2017 Set 2 · Q2
Time

Select one answerSingle correct
Solution
Official answer: A) P → (ii), Q → (iv), R → (i), S → (iii)
Programming in CLet us analyze each item:
(P) static char var;: Static variables are allocated memory in the data section (specifically the BSS/initialized data segment) of memory. Thus, P (ii).
(Q) m = malloc(10); m = NULL;: Memory allocated dynamically using malloc is orphaned when the pointer m is set to NULL without calling free(m). This causes a memory leak, which is lost memory that cannot be freed. Thus, Q (iv).
**(R) char *ptr[10];: This declares an array of 10 pointers to char, which is a contiguous sequence of memory locations used to store addresses. Thus, R (i)**.
(S) register int var1;: The register storage class is a hint/request to the compiler to store the variable in a CPU register for faster access. Thus, S (iii).
Matching combination: P (ii), Q (iv), R (i), S (iii), which corresponds to option A.
Try the question first, then check your work.
Examiner trap
Consider the memory segment used by static variables, the consequence of overwriting an un-freed malloc pointer, array-of-pointers declarations, and the register keyword.
This Programming in C previous year question is Q2 of the GATE CSE 2017 Set 2 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 20 of them are 1-mark MCQs like this one, and GATE CSE 2017 Set 2 has 6.
How GATE tests Programming in CIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.