本文介绍了在 C 中,一个布尔值(布尔值)占用多少空间?它是 1 位、1 字节还是其他?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 C 中,一个 bool(布尔值)占用多少空间?它是 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 ", 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.
大小不能小于一个字节.但是大于一个字节是合法的.
The size cannot be smaller than one byte. But it would be legal to be larger than one byte.
更多推荐
在 C 中,一个布尔值(布尔值)占用多少空间?它是 1 位、1 字节还是其他?
发布评论