gpt4 book ai didi

c++ - 为什么是 0022FF08 + sizeof(int) = 0022FF0C 而不是 0022FF0A?

转载 作者:行者123 更新时间:2023-11-30 21:18:52 26 4
gpt4 key购买 nike

char是 1 字节增量。 int是 2 字节增量。 float是 4 字节增量。 double是8字节增量。为什么int在这里增加4字节

Hex Increment Program

Hex Increment Output

最佳答案

试试这个:

int i;
...
printf("%d",sizeof(i));

你得到了什么?最有可能 4. 为什么?因为你的CPU很可能是32位的。 2 字节 int 在较旧的 CPU 上是正确的...

永远不要根据“应该”来假设变量的大小,始终使用 sizeof()!

关于c++ - 为什么是 0022FF08 + sizeof(int) = 0022FF0C 而不是 0022FF0A?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12968615/

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