a Unix-like operating system produces the following runtime error: $ gcc segfault.c -g -o segfault $ ./segfault Segmentation fault Backtrace of the core file from GDB: Program received signal SIGSEGV, Segmentation fault. 0x1c0005c2 in main () at segfault.c:6 6 *s = 'H'; This code can be corrected by using an array instead of a character pointer, as this allocates memory on stack and initializes it to the value of the string literal: char s[] = "hello world"; s[0] = 'H'; // equivalently, *s = 'H'; Even though string literals should not be modified (this has undefined behavior in the C standard), in C they are of static char [] type, so there is no implicit conversion in the original code (which points a char * at that array), while in C++ they are of static const char [] type, and thus there is an implicit conversion, so compilers will generally catch this particular error. Null pointer dereference In C and C-like languages, null pointers are used to mean "pointer to no object" and as an error indicator, and dereferencing a null pointer (a read or write through a null pointer) is a very common program error. The C standard does not say that the null pointer is the same as the pointer to memory address 0, though that may be the case in practice. Most operating systems map the null pointer's address such that accessing it causes a segmentation fault. This behavior is not guaranteed by the C standard. Dereferencing a null pointer is undefined behavior in C, and a conforming implementation is allowed to assume that any pointer that is dereferenced is not null. int *ptr = NULL; printf("%d", *ptr); This sample code creates a null pointer, and then tries to access its value (read the value). Doing so causes a segmentation fault at runtime on many operating systems. Dereferencing a null pointer and then assigning to it (writing a value to a non-existent target) also usually causes a segmentation fault: int *ptr = NULL; *ptr = 1; The following code includes a null pointer dereference, but when compiled will often not result in a segmentation fault, as the value is unused and thus the dereference will often be optimized away by dead code elimination: int *ptr = NULL; *ptr; Buffer overflow The following code accesses the character array s beyond its upper boundary. Depending on the compiler and