What is the result of calling free twice on the same pointer?
-
A
The block is simply released again
-
B
A compile-time error in every compiler
-
C
The pointer is set to NULL for you
-
D
Undefined behaviour and possible heap damage
Correct answer
Correct answer
D. Undefined behaviour and possible heap damage
13 views
Explanation
A double free corrupts allocator state, so the C standard leaves the behaviour undefined.
Reference
Asked in: NTS, PPSC IT, Campus Interviews
Doubts & discussion
Not sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ