64位计算机上int和sizeof int指针的大小 [英] Size of int and sizeof int pointer on a 64 bit machine
问题描述
我只是想知道我怎么知道我的笔记本电脑是64位还是32位机器。 (这是64)。
I was just wondering how can I know if my laptop is 64 or 32 bit machine. (it is a 64).
所以,我考虑打印以下内容:
So, I thought about printing the following:
int main()
{
printf("%d",sizeof(int));
}
结果是4,这看起来很奇怪(因为它是64位机器)
and the result was 4, which seemed weird (since it is a 64 bit machine)
但是,当我打印出来时:
But, when I printed this:
int main()
{
printf("%d",sizeof(int*));
}
结果是8,这更有意义。
the result was 8, which made more sense.
问题是:
因为我使用的是64位机器,所以不应该使用原始类型如int应该使用8 bytes
Since I'm using a 64 bit machine, shouldn't a primitive type such as int should use 8 bytes
(64位),那个sizeof int应该是8?为什么不是这样?
(64 bit) and by that sizeof int should be 8? Why isn't it so?
为什么int * size是8?
And why is the int* size is 8?
有点困惑在这里,
所以提前感谢。
推荐答案
不, sizeof(int)
是实现定义的,通常是4个字节。
No, the sizeof(int)
is implementation defined, and is usually 4 bytes.
另一方面,为了解决超过4GB的内存(32位系统可以做到的),你需要你的指针是8字节宽。 int *
只是将地址保存到内存中的某个地方,而你只能用32位来处理超过4GB的内存。
On the other hand, in order to address more than 4GB of memory (that 32bit systems can do), you need your pointers to be 8 bytes wide. int*
just holds the address to "somewhere in memory", and you can't address more than 4GB of memory with just 32 bits.
这篇关于64位计算机上int和sizeof int指针的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!