Junior — Middle
What are the consequences of attempting to access data via a null pointer?
sobes.tech AI
Answer from AI
Accessing data through a null pointer (nullptr in C++ or NULL in C) leads to undefined behavior of the program. In practice, this usually causes a crash with a segmentation fault or a memory access error, as address 0 typically does not belong to the process and does not contain valid data.
Example:
int* p = nullptr;
int value = *p; // Error: dereferencing a null pointer
This behavior should be avoided by always checking the pointer before use.