> ## 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 with Explicit Values

An enumeration (`enum`) in C is a user-defined data type consisting of a set of named integer constants known as enumerators. While the C compiler defaults to assigning sequential integer values starting from `0`, developers can explicitly assign arbitrary constant integer expressions to any or all enumerators during declaration.

## Syntax

Explicit values are assigned using the assignment operator (`=`) followed by a constant integer expression immediately after the enumerator identifier.

```c theme={"dark"}
enum EnumName {
    ENUMERATOR_A = constant_expression,
    ENUMERATOR_B = constant_expression,
    ENUMERATOR_C // Implicitly assigned
};
```

## Evaluation Rules and Mechanics

When explicitly assigning values to enumerators, the C compiler enforces the following mechanical rules:

1. **Constant Expressions:** The assigned value must be a compile-time integer constant expression. It cannot be a variable or the result of a runtime function call.
2. **Sequential Incrementing:** If an enumerator is declared without an explicit assignment, the compiler automatically assigns it a value equal to the preceding enumerator's value plus one (`+ 1`).
3. **Negative Values:** Enumerators can be explicitly assigned negative integer values. Subsequent unassigned enumerators will increment upwards toward zero.
4. **Non-Unique Values:** C permits multiple enumerators within the same enumeration to hold the exact same integer value.
5. **Non-Linearity:** Explicit values do not need to be declared in ascending or descending order. The compiler evaluates each assignment independently.

## Code Visualization

The following block demonstrates how the compiler evaluates a mix of explicit and implicit enumerator values:

```c theme={"dark"}
enum MixedValues {
    VAL_A = 10,       // Explicitly assigned 10
    VAL_B = 50,       // Explicitly assigned 50
    VAL_C,            // Implicitly assigned 51 (VAL_B + 1)
    VAL_D = -5,       // Explicitly assigned -5
    VAL_E = -5,       // Explicitly assigned -5 (Duplicate value allowed)
    VAL_F,            // Implicitly assigned -4 (VAL_E + 1)
    VAL_G = 0         // Explicitly assigned 0
};
```

## Type Constraints and Representation

The C standard dictates that the expression defining the value of an enumeration constant *must* have a value representable as a standard `int`. Assigning an explicit value that falls outside the representable range of an `int` is a constraint violation and will result in a compilation error. Consequently, all individual enumeration constants are strictly of type `int`.

While the enumerators themselves are always of type `int`, the compiler selects an implementation-defined underlying integer type for the enumeration type as a whole (such as `char`, `signed int`, or `unsigned int`). The compiler guarantees that this chosen underlying type is capable of representing the values of all the enumerators defined within that specific `enum`.

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