在C语言中,布尔值(布尔值)占用多少空间?是1位,1字节还是其他? [英] In C how much space does a bool (boolean) take up? Is it 1 bit, 1 byte or something else?
本文介绍了在C语言中,布尔值(布尔值)占用多少空间?是1位,1字节还是其他?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C语言中,布尔值(布尔值)占用多少空间?是1位,1字节还是其他?程序是32位还是64位有关系吗?
In C how much space does a bool (boolean) take up? Is it 1 bit, 1 byte or something else? Does it matter if the program is 32-bit or 64-bit?
推荐答案
如果您指的是C99 _Bool
,请尝试:
If you are referring to C99 _Bool
try:
printf("%zu\n", sizeof(_Bool)); /* Typically 1. */
请注意标准说明:
6.2.5
声明为类型 _Bool
的对象足够大,可以存储值0和1.
An object declared as type _Bool
is large enough to store the values 0
and 1.
大小不能小于1个字节.但是大于一个字节是合法的.
The size cannot be smaller than one byte. But it would be legal to be larger than one byte.
这篇关于在C语言中,布尔值(布尔值)占用多少空间?是1位,1字节还是其他?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文