What causes 'segmentation fault (core dumped)' in c++?

Example:

int* ptr = nullptr;
*ptr = 10;

This error occurs when trying to access memory that hasn't been allocated or is out of the process's reach.

Solution:

Ensure pointers are initialized before being dereferenced.


int value = 10;
int* ptr = &value;
*ptr = 20;

Beginner's Guide to C++