Question
Match the following:
| Item | Description |
|---|---|
(P) static char var; |
(i) Sequence of memory locations to store addresses |
(Q) m = malloc(10); m = NULL; |
(ii) A variable located in data section of memory |
(R) char *ptr[10]; |
(iii) Request to allocate a CPU register to store data |
(S) register int var1; |
(iv) A lost memory which cannot be freed |
Official answer and solution
- Official answer
- A
- From
- Official GATE 2017 answer key
Solution
Match each C declaration or code snippet with its corresponding memory segment, storage class, or memory behavior.
Analyze each item:
static char var;: Static variables with file or block scope reside in the data section (BSS or initialized data) of the process address space. This matches (ii).m = malloc(10); m = NULL;: Dynamic memory allocated on the heap loses its only pointer reference whenmis set toNULL, resulting in a memory leak where the allocated block cannot be freed. This matches (iv).char *ptr[10];: This declares an array of 10 pointers tochar, which is a sequence of memory locations holding addresses. This matches (i).register int var1;: Theregisterstorage class is a hint/request to the compiler to store the variable in a CPU register for faster access. This matches (iii).
Combining the pairs gives P (ii), Q (iv), R (i), S (iii), which corresponds to option A.
Final answer
A
Common trap
Confusing an array of pointers char *ptr[10] with a pointer to an array char (*ptr)[10].
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2017 Computer Science and Information Technology (CS) Session 2
- Question
- 2 of 65, printed as CS Q.2
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.