Junior — Middle
What will happen if you try to delete a pointer pointing to null using the delete operator?
sobes.tech AI
Answer from AI
In C++, the delete operator safely handles deleting a pointer that is equal to nullptr (null). If you attempt to call delete on a pointer that is null, nothing will happen — the operation is simply ignored.
Example:
int* p = nullptr;
delete p; // Safe, nothing will happen
This behavior is guaranteed by the C++ standard and allows you to avoid checking for null before deleting.