在 C 中,一个布尔值(布尔值)占用多少空间?它是 1 位、1 字节还是其他?

编程入门 行业动态 更新时间:2024-10-05 19:14:54
本文介绍了在 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 字节还是其他?

本文发布于:2023-11-03 04:07:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554203.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布尔值   它是   字节   空间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!