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.
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