Open In App
Related Articles

C | Dynamic Memory Allocation | Question 1

Improve Article
Improve
Save Article
Save
Like Article
Like

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)

Explanation: 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


Quiz of this Question

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Similar Reads