long 和 int 数据类型之间的区别

2022-01-14 00:00:00 integer types size c++

考虑到以下语句返回4,C++中的intlong类型有什么区别?

Considering that the following statements return 4, what is the difference between the int and long types in C++?

sizeof(int)
sizeof(long)

推荐答案

来自 this 参考:

一个 int 原本打算是的自然"字长处理器.许多现代处理器可以以相等的方式处理不同的字长轻松.

An int was originally intended to be the "natural" word size of the processor. Many modern processors can handle different word sizes with equal ease.

还有,这一点:

在许多(但不是全部)C 和 C++ 上实现,长大于一个整数.当今最流行的桌面平台,如 Windows 和 Linux,主要运行在 32 位处理器和这些平台的大多数编译器使用具有相同大小的 32 位 int并以长表示.

On many (but not all) C and C++ implementations, a long is larger than an int. Today's most popular desktop platforms, such as Windows and Linux, run primarily on 32 bit processors and most compilers for these platforms use a 32 bit int which has the same size and representation as a long.

相关文章