保证 C 数据类型的最小大小/范围 [英] Guarantateed minimum size/range of C data types
本文介绍了保证 C 数据类型的最小大小/范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于这个问题,我找到了不同的答案,我知道肯定只有一个答案.C 中四种主要数据类型的最小分配内存大小是多少?int
、double
、float
和 char
是我想到的.signed
或 unsigned
类型是否以任何方式改变大小?
I have found varying answers to this question, and I know there must be one definitive answer. What is the minimum allocated memory size of the four main data types in C? int
, double
, float
, and char
are what I'm thinking of. Do the signed
or unsigned
types alter the size in any way?
推荐答案
你可以使用sizeof(variable)
:
作为在我的本地机器上运行的示例:
As an example running this on my local machine:
sizeof (char) = 1
sizeof (double) = 8
sizeof (float) = 4
sizeof (int) = 4
sizeof (long) = 4
sizeof (long long) = 8
sizeof (short) = 2
sizeof (void *) = 4
注意:您得到的值可能由操作系统/编译器/CPU 架构决定.
Note: the values you get may be determined by OS/Compiler/CPU architecture.
这篇关于保证 C 数据类型的最小大小/范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文