Discussion
On freeing a dynamic memory, if the pointer value is not modified, then the pointer points to?
Answer: C
Correct answer: The same deallocated memory location
free receives the pointer by value and cannot alter the caller's copy, so the bits in the pointer are exactly what they were. It still holds the address of the block - which now belongs to the allocator again.
This is a dangling pointer, and it is dangerous precisely because it looks valid and may appear to work while the freed block is untouched. Setting the pointer to NULL immediately after freeing is the standard discipline, since a null dereference fails immediately and visibly.
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