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.
它的 C 程序正在运行 x86_64 机器,想知道输出是如何这样的
main() { int *mess; mess=malloc(1); mess[0]=1; //mess[1]=2; printf("%d",mess); }
现在这里的输出是 6295568
如何??
您正在打印存储 int 的地址。你需要
printf("%d",*mess);
打印它的值。
您还为您的 int 分配了太少的空间,您应该这样做:
int *mess = malloc(sizeof(int));
代替
int *mess = malloc(1);