A segfault occurs when a program attempts to access a memory location that is not allowed to access, or attempts to access a memory location in a way is not allowed.
// segfault.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string.h> int _tmain(int argc, _TCHAR* argv[]) { char a[2]; char b[] = "Hello world!"; memcpy(a, b, strlen(b)); return 0; }
上述示例也就是我们常说的越界访问!