Junior
What happens if you call the free function for a pointer that is equal to nullptr?
sobes.tech AI
Answer from AI
Nothing will happen. The C standard specifies that calling free with a nullptr argument has no effect.
C Standard, section 7.22.3.3:
The
freefunction causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs.
C++ Standard, section 21.6.7.3 (for std::free in <cstdlib>):
If
ptris a null pointer, the function does nothing.