_Bool C99 Boolean type

_Bool C99 Boolean type

C99's _Bool normalizes scalars to 0 for zero and 1 for nonzero. stdbool.h supplies bool, true, and false; conditions accept any scalar, not only _Bool.

CategoryType specifiers
KindKeyword / Statement
C standardC99

📝 Syntax

_Bool b = 1;  /* Or include <stdbool.h> and use bool b = true; */

▶ Example

Edit the C code below and click Run; the server compiles and executes it:

Output:

raw = 1, named = 1, empty = 0

📚 Related Tutorials

❓ FAQ

QDoes a _Bool variable store 5 after being assigned 5?
ANo. Converting any nonzero scalar to _Bool normalizes it to 1, while zero becomes 0. Reading the object can therefore yield only the Boolean values 0 or 1.
QWhat is the difference between bool and _Bool?
A_Bool is the built-in C99 type keyword. bool is a macro supplied by stdbool.h that expands to _Bool, so declarations using either name have the same type after that header is included.
QWhy are true and false reported as undefined?
AIn C99 and C11, true and false are macros from stdbool.h, not built-in keywords. Add #include <stdbool.h>, or use _Bool directly with 0 and 1.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏