Segmentation fault (core dumped)
The program tried to access memory it doesn't have permission to access.
free
)int main() { int *ptr = NULL; *ptr = 10; // Dereferencing NULL pointer return 0; }
Check pointers before dereferencing them and ensure array accesses are within bounds.
#include <stdlib.h> int main() { int *ptr = malloc(sizeof(int)); if (ptr != NULL) { *ptr = 10; free(ptr); } return 0; }
malloc
/calloc
returned NULL before using the pointerValgrind
to detect memory errorsNULL
after freeing them to avoid dangling pointers