Skip to content
Official PYQ · 2017

GATE CS 2017 Set 2 Q2 — Programming in C

Explain with AI

Match the following:P.static char var ;i.Sequence of memory locations to store addressesQ.m = malloc(10); m =NULL ;ii.A variable located in data section of memoryR.char *ptr[10] ;iii.Request to allocate a CPU register to store dataS. register int varl;iv.A lost memory which cannot be freed\begin{array}{|ll|ll|}\hline P. & \text{static char var ;} & \text{i.} & \text{Sequence of memory locations to store addresses} \\ \hline Q. & \text{m = malloc(10); m =NULL ;} & \text{ii.} & \text{A variable located in data section of memory} \\ \hline R. & \text{char *ptr[10] ;} & \text{iii.} & \text{Request to allocate a CPU register to store data} \\ \hline S. & \text{ register int varl;} & \text{iv.} & \text{A lost memory which cannot be freed} \\ \hline\end{array}

Choose one option
View worked solution

Answer: A

We can match each C programming construct to its corresponding description as follows:

  • P. static char var; → ii. A variable located in data section of memory
    Static variables in C have static storage duration. They are allocated in the data segment (specifically, uninitialized static variables are placed in the BSS segment, which is a part of the data section) and persist for the entire lifetime of the program.

  • Q. m = malloc(10); m = NULL; → iv. A lost memory which cannot be freed
    Memory is dynamically allocated on the heap using malloc. By reassigning the pointer m to NULL without first calling free(m), the address of the allocated block is lost. This causes a memory leak, as the allocated memory can no longer be accessed or deallocated.

  • R. char *ptr[10]; → i. Sequence of memory locations to store addresses
    This defines an array of 10 pointers to char. Since pointers store memory addresses, this array represents a contiguous sequence of memory locations designed to store addresses.

  • S. register int varl; → iii. Request to allocate a CPU register to store data
    The register storage class specifier is a hint/request to the compiler to store the variable in a CPU register rather than in RAM, to enable faster access.

Thus, the correct matching is:
P → ii, Q → iv, R → i, S → iii, which corresponds to Option A.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Programming in C questions