Q:

What are the common causes of segmentation fault in C?

0

What are the common causes of segmentation fault in C?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

There are many reasons for the segmentation fault, here I am listing some common causes of the segmentation fault.

  • Dereferencing NULL pointers.
  • Tried to write read-only memory (such as code segment).
  • Trying to access a nonexistent memory address (outside process’s address space).
  • Trying to access memory the program does not have rights to (such as kernel structures in process context).
  • Sometimes dereferencing or assigning to an uninitialized pointer (because might point an invalid memory) can be the cause of the segmentation fault.
  • Dereferencing the freed memory (after calling the free function) can also be caused by the segmentation fault.
  • A stack overflow is also caused by the segmentation fault.
  • A buffer overflow (try to access the array beyond the boundary) is also a cause of the segmentation fault.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Embedded C interview questions and answers (2022)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What is the difference between Segmentation fault ... >>
<< What is segmentation fault in C?...