在 C 中,一个布尔值(布尔值)占用多少空间?它是 1 位、1 字节还是其他? [英] In C how much space does a bool (boolean) take up? Is it 1 bit, 1 byte or something else?

查看:12
本文介绍了在 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 字节还是其他?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆