> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C _Bool

`_Bool` is a built-in unsigned integer type introduced in the C99 standard, designed specifically to represent boolean truth values. Unlike standard integer types, `_Bool` enforces strict boolean semantics at the language level: it is only capable of storing the values `0` or `1`.

## Syntax and Implicit Conversion

The most defining characteristic of `_Bool` is its implicit conversion rules. When any scalar value (integer, floating-point, or pointer) is assigned to a `_Bool` variable, the compiler automatically normalizes the value. Any non-zero value or non-null pointer evaluates to `1`, while a zero value or null pointer evaluates to `0`.

```c theme={"dark"}
_Bool flag_zero  = 0;       // Stores 0
_Bool flag_one   = 1;       // Stores 1

// Implicit conversion examples
_Bool flag_int   = 42;      // Evaluates to 1
_Bool flag_neg   = -99;     // Evaluates to 1
_Bool flag_float = 0.001f;  // Evaluates to 1
_Bool flag_null  = '\0';    // Evaluates to 0

int* ptr = 0;               // Null pointer
_Bool flag_ptr   = ptr;     // Evaluates to 0
```

This behavior prevents overflow issues that occur when using standard `int` or `char` types for boolean logic, where assigning a value like `256` to an 8-bit integer might truncate to `0`.

## Memory Representation

The C standard dictates that `_Bool` must be large enough to store the values `0` and `1`. While the exact memory footprint is implementation-defined, `sizeof(_Bool)` is typically `1` byte (8 bits) on modern architectures. This is because `1` byte is the smallest individually addressable unit of memory for most CPUs.

```c theme={"dark"}
#include <stdio.h>

int main(void) {
    // Typically outputs: Size of _Bool: 1 byte(s)
    printf("Size of _Bool: %zu byte(s)\n", sizeof(_Bool)); 
    return 0;
}
```

## The `<stdbool.h>` Abstraction

While `_Bool` is the native language keyword, C99 also introduced the `<stdbool.h>` header to provide a more conventional syntax that aligns with C++ and other modern languages. This header defines three macros that map directly to the `_Bool` type and its binary states.

```c theme={"dark"}
#include <stdbool.h>

/* 
Underlying macro definitions in <stdbool.h>:
#define bool  _Bool
#define true  1
#define false 0
*/

bool is_ready = true;
bool is_done  = false;
```

## Integer Promotion

Because `_Bool` is classified as an integer type, it is subject to standard integer promotion rules. When a `_Bool` is used in an arithmetic expression, it is promoted to an `int` before the operation is evaluated.

```c theme={"dark"}
_Bool a = 1;
_Bool b = 1;

// 'a' and 'b' are promoted to int (1 + 1). 
// The result is 2, which is stored in 'result'.
int result = a + b; 

// If assigned back to a _Bool, the result (2) is implicitly converted back to 1.
_Bool combined = a + b; 
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
