GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 46

Match the following List-I and List-II:

List-I List-II
P. Memory Leak 1.

#include 
  
void fun(int x) 
{ 
    if (x == 1) 
       return; 
    x = 6; 
    fun(x); 
} 
  
int main() 
{ 
   int x = 5; 
   fun(x); 
} 
Q. Dangling Pointer 2.

char* func()
{
   char str[10];
   strcpy(str,"Hello!");
   return(str); 
}
R. Stack Overflow 3.

#include < stdlib.h >

  void f() {
    int * ptr = (int * ) malloc(sizeof(int));
    /* Do some work */
    return;
  }
S. Wild Pointer 4.



int main() 
{ 
  int  *p; 
  int a = 10; 
  p = &a;  
  *p = 12; 
} 


(A) P – 1, Q – 4, R – 3, S – 2
(B) P – 1, Q – 2, R – 3, S – 4
(C) P – 3, Q – 4, R – 1, S – 2
(D) P – 3, Q – 2, R – 1, S – 4


Answer: (D)

Explanation: Memory leak occurs when programmers create a memory in heap and forget to delete it.

A pointer pointing to a memory location that has been deleted (or freed) is called dangling pointer.

If function recursively call itself infinite times then the stack is unable to store large number of local variables used by every function call and will result in overflow of stack.

A pointer which has not been initialized to anything (not even NULL) is known as wild pointer. The pointer may be initialized to a non-NULL garbage value that may not be a valid address.

Therefore, P – 3, Q – 2, R – 1, S – 4.

Option (D) is correct.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.