List of Common Reasons for Segmentation Faults in C/C++


The main reason for segmentation fault is accessing memory that is either not initialized, out of bounds for your program or trying to modify string literals. These may cause a segmentation fault though it is not guaranteed that they will cause a segmentation fault. Here are some of the common reasons for segmentation faults:

  1. Accessing an array out of bounds
  2. Dereferencing NULL pointers
  3. Dereferencing freed memory
  4. Dereferencing uninitialized pointers
  5. Incorrect use of the "&" (address of) and "*" (dereferencing) operators
  6. Improper formatting specifiers in printf and scanf statements
  7. Stack overflow
  8. Writing to read-only memory
raja
Published on 28-Feb-2018 16:01:06
Advertisements