"Segmentation fault (core dumped)" is the C programmer's rite of passage.
Direct answer
A segmentation fault means your program tried to read or write memory it does not own. Common causes are dereferencing a NULL or uninitialised pointer, writing past an array, using memory after free and endless recursion. Use gdb or AddressSanitizer to find the exact line.
Typical bugs
int *p = NULL;
*p = 5; // crash
int arr[3];
arr[10] = 1; // out of bounds
char *s = "hello";
s[0] = 'H'; // string literals are read-only
How to debug
gcc -g -fsanitize=address main.c -o app
./app
Or with gdb:
gcc -g main.c -o app
gdb ./app
(gdb) run
(gdb) bt
Prevention
- Initialise pointers to
NULLand check before use. - Check array bounds.
- Free memory once and set pointers to
NULL.
Where Teyro fits
Teyro's C for Beginners course turns this into short lessons you can play in a few minutes a day. It has 78 lessons, and you can start free.
The bottom line
Find the line, find the pointer, fix the assumption.



