Discussion
The most appropriate matching for the following pairs
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:
Answer: D
Correct answer: X-3 Y-1 Z-2
Take each line in turn. X allocates memory and then overwrites the only pointer to it with NULL, so the block can never be freed - that is lost memory, a leak, giving X-3.
Y frees the block and then writes through the same pointer, which now refers to memory the allocator has reclaimed - a dangling pointer, giving Y-1. Z declares a pointer without ever assigning it an address and writes through it, which is an uninitialised pointer, giving Z-2. The three are the classic pointer faults.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development