Saturday, 25 February 2017

The most appropriate matching for the following pairs (GATE CS 2000)


X: m=malloc(5); m= NULL;        1: using dangling pointers
Y: free(n); n->value=5;         2: using uninitialized pointers
Z: char *p; *p = ’a’;           3. lost memory is:

(a) X—1 Y—3 Z-2
(b) X—2 Y—1 Z-3
(C) X—3 Y—2 Z-1
(d) X—3 Y—1 Z-2

Answer (d)
X -> A pointer is assigned to NULL without freeing memory so a clear example of memory leak
Y -> Trying to retrieve value after freeing it so dangling pointer.
Z -> Using uninitialized pointers

No comments:

Post a Comment