> ## 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 Enum Declaration

An enumeration (`enum`) is a user-defined data type consisting of a set of named integer constants known as enumerators. In C, individual enumerators are strictly of type `int`, while the enumeration type itself is represented by an implementation-defined integer type capable of holding all defined enumerator values.

## Syntax

```c theme={"dark"}
enum [tag_name] {
    enumerator_1 [= constant_expression],
    enumerator_2 [= constant_expression],
    /* ... */
} [variable_list];
```

* **`tag_name`**: An optional identifier that names the enumeration type.
* **`enumerator_list`**: A comma-separated list of identifiers. A trailing comma is permitted in modern C (C99 onwards).
* **`variable_list`**: An optional comma-separated list of variable instances declared immediately alongside the type definition.

## Declaration Patterns

**1. Tagged Declaration**
Defines the enumeration type using a tag. Subsequent variable declarations must include the `enum` keyword.

```c theme={"dark"}
enum State {
    IDLE,
    RUNNING,
    HALTED
};

enum State current_state;
```

**2. Anonymous Declaration**
Omits the tag. Variables must be declared immediately within the statement, or the declaration serves solely to inject the enumerator constants into the current scope.

```c theme={"dark"}
enum {
    READ_MODE,
    WRITE_MODE
} file_mode;
```

**3. Typedef Declaration**
Aliases the enumeration type to a new identifier, eliminating the need to use the `enum` keyword during variable instantiation.

```c theme={"dark"}
typedef enum {
    TCP,
    UDP
} Protocol;

Protocol network_proto;
```

## Enumerator Value Assignment

By default, the compiler assigns the integer value `0` to the first enumerator and increments the value by `1` for each subsequent enumerator. This behavior can be overridden by assigning explicit integer constant expressions.

```c theme={"dark"}
enum Configuration {
    MAX_CONNECTIONS = 100,  // Explicitly 100
    TIMEOUT = 50,           // Explicitly 50
    RETRY_LIMIT,            // Implicitly 51 (TIMEOUT + 1)
    DEFAULT_PORT = 8080,    // Explicitly 8080
    ALT_PORT                // Implicitly 8081 (DEFAULT_PORT + 1)
};
```

*Note: Multiple enumerators within the same declaration are permitted to hold identical integer values.*

## Scope and Namespace Rules

* **Enumerator Scope:** Enumerators are injected directly into the enclosing scope of the `enum` declaration. C does not support scoped enumerations; accessing an enumerator via its tag (e.g., `State.IDLE`) is a syntax error. The identifier is simply `IDLE`.
* **Identifier Uniqueness:** Because enumerators leak into the enclosing scope, two different enumerations within the same scope cannot share an enumerator identifier.
* **Tag Namespace:** The `tag_name` occupies the C tag namespace (shared with `struct` and `union`). It can share an identifier with a variable or function, but it cannot share an identifier with another struct, union, or enum tag in the same scope.

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