首页 > 编程语言 > 详细

C语言 segment fault

时间:2016-01-25 19:11:55      阅读:314      评论:0      收藏:0      [点我收藏+]

Segmentation fault is a specific kind of error caused by accessing memory that “does not belong to you.” It’s a helper mechanism that keeps you from corrupting the memory and introducing hard-to-debug memory bugs. Whenever you get a segfault you know you are doing something wrong with memory – accessing variable that has already been freed, writing to a read-only portion of the memory, etc. Segmentation fault is essentially the same in most languages that let you mess with the memory management, there is no principial difference between segfaults in C and C++.

There are many ways to get a segfault, at least in the lower-level languages such as C(++). A common way to get a segfault is to dereference a null pointer:

以上文字转自:http://stackoverflow.com/questions/2346806/what-is-segmentation-fault

int main(){

char* str = "Foo";

*str = ‘a‘;

}

int main(){

char* str = NULL;

*str = ‘a‘;

}

以上两个程序会报segment fault

 

C语言 segment fault

原文:http://www.cnblogs.com/weplaysoft/p/Segment_fault.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!