> ## 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 Default Label

The `default` keyword in C serves as a fallback execution path within a `switch` statement or as the default type association in a C11 `_Generic` selection. Within a `switch` statement, the `default` label acts as the target for control flow when the evaluated integer expression of the control block does not equal any of the defined `case` constant expressions.

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

// _Generic selection usage (C11+)
#define TYPE_CHECK(x) _Generic((x), \
    int: 1, \
    default: 0 \
)

int main(void) {
    int expression = 5;
    
    // switch statement usage
    switch (expression) {
        case 1:
            printf("One\n");
            break;
        default:
            printf("Default fallback\n");
            break;
    }

    int is_int = TYPE_CHECK(3.14);
    printf("Is int: %d\n", is_int); // Outputs 0

    return 0;
}
```

## Technical Characteristics

**Uniqueness**
A single `switch` statement or `_Generic` selection may contain a maximum of one `default` label or association. Multiple `default` labels can legally exist within the same lexical scope, provided they belong to strictly separate `switch` statements or `_Generic` selections.

**Optionality**
The `default` keyword is not required. If a `switch` statement lacks a `default` label and the evaluated expression does not match any `case` label, the control flow simply bypasses the entire `switch` statement, and no internal statements are executed. In a `_Generic` selection, omitting `default` when no specified type matches the controlling expression results in a compilation error.

**Position Independence and Evaluation**
The C standard does not mandate the physical placement of the `default` label within a `switch` statement. It can be positioned at the beginning, middle, or end. `case` expressions are integer constant expressions evaluated at compile time. At runtime, the controlling expression of the `switch` is evaluated exactly once, and control is transferred directly to the matching label (often optimized via a jump table). If no `case` constant matches the evaluated expression, control transfers directly to the `default` label, regardless of its lexical position.

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

int main(void) {
    int value = 2;
    
    switch (value) {
        default: 
            printf("Default executed\n"); 
            break;
        case 1: 
            printf("Case 1 executed\n"); 
            break;
    }
    
    return 0;
}
```

**Fallthrough Behavior**
Inside a `switch` statement, the `default` label is subject to the same lexical control flow rules as `case` labels. If the `default` block is executed and is not explicitly terminated by a jump statement (such as `break`, `return`, or `goto`), execution will "fall through" into the lexically subsequent `case` block, ignoring that block's constant expression.

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

int main(void) {
    int value = 5;
    
    switch (value) {
        case 1:
            printf("Case 1\n");
            break;
        default:
            printf("Default\n");
            // Missing break; execution falls through to case 2
        case 2:
            printf("Case 2\n");
            break;
    }
    
    return 0;
}
```

## Scope and Constraints

* When used as a control flow label, `default` must be associated with a `switch` statement. However, the C standard dictates that a `switch` takes a `statement`, which does not strictly have to be a compound statement (block). A single statement prefixed by `default` is perfectly valid C.

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

int main(void) {
    int x = 10;
    // Valid C: switch with a single non-compound statement
    switch (x) default: puts("fallback");
    return 0;
}
```

* In C89 through C17, a label must strictly precede a statement. If the `default` label is the final item in a `switch` block, it must be followed by a null statement (`;`) or a jump statement (e.g., `break;`) to satisfy the compiler's syntax rules.
* C23 introduced free-standing labels (N2508), which allows the `default` label to appear at the end of a compound statement without requiring a trailing statement.

<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>
