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

CC++Server Side ProgrammingProgramming

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 −

  • Accessing an array out of bounds
  • Dereferencing NULL pointers
  • Dereferencing freed memory
  • Dereferencing uninitialized pointers
  • Incorrect use of the "&" (address of) and "*" (dereferencing) operators
  • Improper formatting specifiers in printf and scanf statements
  • Stack overflow
  • Writing to read-only memory
raja
Published on 28-Feb-2018 11:31:06
Advertisements