What should be the sizeof(int) on a 64-bit machine? [duplicate]

半城伤御伤魂 提交于 2019-11-27 11:32:08

Doesn't have to be; "64-bit machine" can mean many things, but typically means that the CPU has registers that big. The sizeof a type is determined by the compiler, which doesn't have to have anything to do with the actual hardware (though it typically does); in fact, different compilers on the same machine can have different values for these.

Size of a pointer should be 8 byte on any 64-bit C/C++ compiler, but not necessarily size of int.

Not really. for backward compatibility it is 32 bits.
If you want 64 bits you have long, size_t or int64_t

In C++, the size of int isn't specified explicitly. It just tells you that it must be at least the size of short int, which must be at least as large as signed char. The size of char in bits isn't specified explicitly either, although sizeof(char) is defined to be 1. If you want a 64 bit int, C++11 specifies long long to be at least 64 bits.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!