【发布时间】:2012-02-17 02:37:36
【问题描述】:
请根据下面的代码告诉我堆栈和堆之间的区别
int main()
{
int arr[3];
int *a;
arr [5] = 6; // out of bound but it will not give error.
arr [3000] = 8 ; //SIGSEGV
a = malloc (sizeof (int));
a[4] = 6;
a[4000] = 8; //No error
}
我知道 arr 是一个静态数组,当我执行 arr[3000] 时,我正在访问其他进程的地址,这会产生 SIGSEGV 错误。但我不明白为什么 a[4000] 不会给我任何运行时错误,即 SIGSEGV 信号。
谢谢
【问题讨论】:
标签: c linux malloc undefined-behavior allocator