Junior
What happens if you call free on a nullptr pointer?
sobes.tech AI
Answer from AI
Calling free on a pointer that is equal to nullptr does not lead to an error or program crash. The C and C++ language standards guarantee this behavior. The free function simply does nothing in this case.
#include <cstdlib> // For free
int main() {
int* ptr = nullptr;
free(ptr); // Safe
return 0;
}