Q:

CAN A POINTER BE FREED MORE THAN ONCE IN C? WHAT HAPPENS IF DO SO? OR CAN A POINTER BE FREED TWICE IN C?

belongs to collection: C INTERVIEW QUESTIONS AND ANSWERS

0

CAN A POINTER BE FREED MORE THAN ONCE IN C? WHAT HAPPENS IF DO SO? OR CAN A POINTER BE FREED TWICE IN C?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

1st scenario: After freeing a pointer in a C program, freed memory might be reallocated by some other or same program luckily. In this scenario, freeing the same pointer twice won’t cause any issue.

2nd scenario: We can free a pointer. Then, we can allocate memory for same pointer variable. Then, we can use it and free it again. This is also not an issue.

3rd scenario: If we free the same pointer second time without reallocating memory to that pointer, then what happens? As per ANSI/ISO C standard, this is undefined behaviour. This undefined behaviour may cause anything to the program that we do not expect to happen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C INTERVIEW QUESTIONS AND ANSWERS

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
WHAT IS THE SIZE OF INT POINTER AND CHAR POINTER I... >>
<< WHAT IS MEANT BY CORE DUMP IN C?...