Practice mode C Language

What happens when free(NULL) is called in C?

Correct answer D. Nothing; the call has no effect

Explanation

The C standard states that if the argument to free is a null pointer, no action occurs. This lets clean-up code call free on pointers that may never have been allocated without checking first. Setting a pointer to NULL after freeing it is a common habit for this reason, because freeing the same non-null pointer twice is undefined behaviour.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.