gpt4 book ai didi

c - 为什么每次编译内存地址都在变?

转载 作者:太空宇宙 更新时间:2023-11-04 02:57:23 25 4
gpt4 key购买 nike

为什么指向的地址一直在变?发生这种情况的内存内部发生了什么,或者我的 printf 语句有问题吗?

#include <stdio.h>
#include <stdlib.h>

int main()
{

char blocks[3] = {'A', 'B', 'C'};

char *ptr = &blocks[0];

char temp;

temp = blocks[0];
printf(" %c, %d ", temp, &temp);

return 0;
}

输出

A, 1764940775 
A, 1731746791

最佳答案

看起来您的堆栈指针是随机的。我怀疑这是因为在大多数较新的操作系统中用作安全机制的地址空间布局随机化。

关于c - 为什么每次编译内存地址都在变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15916174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com