Long Vs. Int C/C++ - What#39;s The Point?(长与.诠释 C/C++ - 有什么意义?)
问题描述
我最近了解到,C/C++ 中的 long
与 int
的长度相同.简单地说,为什么?甚至在语言中包含数据类型似乎几乎毫无意义.它是否有任何 int
没有的特定用途?我知道我们可以像这样声明一个 64 位 int
:
As I've learned recently, a long
in C/C++ is the same length as an int
. To put it simply, why? It seems almost pointless to even include the datatype in the language. Does it have any uses specific to it that an int
doesn't have? I know we can declare a 64-bit int
like so:
long long x = 0;
但是为什么语言选择这样做,而不是仅仅使 long
好...比 int
长?其他语言(例如 C#)可以做到这一点,那么为什么不使用 C/C++?
But why does the language choose to do it this way, rather than just making a long
well...longer than an int
? Other languages such as C# do this, so why not C/C++?
推荐答案
使用 C 或 C++ 编写时,每种数据类型都是特定于体系结构和编译器的.在一个系统上 int 是 32,但您可以找到它是 16 或 64 的系统;它没有定义,所以由编译器决定.
When writing in C or C++, every datatype is architecture and compiler specific. On one system int is 32, but you can find ones where it is 16 or 64; it's not defined, so it's up to compiler.
至于 long
和 int
,它来自时代,标准整数是 16 位,而 long
是 32 位整数 - 而且它确实 比 int
长.
As for long
and int
, it comes from times, where standard integer was 16bit, where long
was 32 bit integer - and it indeed was longer than int
.
这篇关于长与.诠释 C/C++ - 有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:长与.诠释 C/C++ - 有什么意义?


- C++ 协变模板 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 从python回调到c++的选项 2022-11-16