Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在阅读一篇关于为指针分配空间的文章,该文章并未确切说明“程序中断”是什么,但提到了它。我需要知道程序中断是什么。如果我用 malloc 创建一个指向内存空间的指针..IE
char *ptr = (char*)malloc(100);
PROGRAM BREAK 是开始还是结束?是 p[0] 还是 p[99] 的地址 THX
好吧,程序中断是初始化数据段的结束,因此,它通常在其他地方:
#include <unistd.h> #include <stdlib.h> #include <stdio.h> int main() { char *ptr = (char*)malloc(100); printf("%p %p %p\n", ptr, ptr+100, sbrk(0)); return 0; }
输出:
0x744010 0x744074 0x765000
实际值取决于运行时内存分配器(又名malloc)使用的策略。
malloc