Home >Backend Development >C++ >What's the Size of a Boolean Variable (bool) in C ?

What's the Size of a Boolean Variable (bool) in C ?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-20 21:03:11351browse

What's the Size of a Boolean Variable (bool) in C  ?

Determining the Size of 'bool' in C

The C standard does not explicitly define the size of the 'bool' data type. This means that the size of 'bool' is left to the implementation of the compiler.

Implementation-Defined Size

The C language standard states that the size of any fundamental type, except for 'char', 'signed char', and 'unsigned char', is implementation-defined. This includes the 'bool' data type. Therefore, the size of 'bool' can vary depending on the compiler being used.

Further Clarification

In §5.3.3/1 of the C standard, it is explicitly stated that "the result of sizeof applied to any other fundamental type is implementation-defined." Footnote 69 further emphasizes this point by stating that "sizeof(bool) is not required to be 1."

Conclusion

The size of 'bool' in C is not guaranteed to be 1. It is an implementation-defined characteristic, which means that its size can vary depending on the compiler.

The above is the detailed content of What's the Size of a Boolean Variable (bool) in C ?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn