Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

Segmentation fault ใน C/C++ คืออะไร


Segmentation fault เกิดเมื่อโปรแกรมพยายาม access พื้นที่หน่วยความจำที่ไม่ได้รับอนุญาต กล่าวคือ พยายาม access memory ที่เกินขีดจำกัดที่ OS จัดสรรให้

Segmentation faults เกิดจาก pointers ที่:

  • Used to being properly initialized. (หมายถึง: ไม่ได้ initialize อย่างถูกต้อง)

  • Used after the memory they point to has been reallocated or freed.

  • Used in an indexed array where the index is outside of the array bounds.