Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 4 : Undefined behavior that may corrupt the heap

Advertisement

Detailed Solution

सही उत्तर Undefined behavior that may corrupt the heap है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

In C, what happens when free() is called twice on the same pointer without any reallocation in between? / C में, बीच में कोई पुनः आवंटन किए बिना एक ही पॉइंटर पर free() दो बार कॉल करने पर क्या होता है?

1.
The second call is safely ignored
2.
The pointer is automatically set to NULL
3.
The memory block is freed twice with no side effects
4.
Undefined behavior that may corrupt the heap

Correct Answer: Undefined behavior that may corrupt the heap

A double free is undefined behavior in C; it can corrupt the heap's free-list metadata and crash the program. free() never modifies the pointer itself. / C में डबल free अपरिभाषित व्यवहार है; यह हीप के free-list मेटाडेटा को भ्रष्ट कर प्रोग्राम क्रैश करा सकता है। free() पॉइंटर को स्वयं कभी नहीं बदलता।

Downloaded from PrepSnap (prepsnap.in)