C Enums

Named integer constants.

✍️ 2 exercises in this lesson

An enum defines a set of named integer constants, making code easier to read.

enum Level { LOW, MEDIUM, HIGH };: LOW is 0, MEDIUM 1, HIGH 2. You can assign your own values too.

Key Takeaways: C Enums

Mastering C Enums helps you write clean and reliable C code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

C Enums Code Example

C
#include <stdio.h>

enum Status { PENDING = 1, SHIPPED, DELIVERED };

int main() {
    enum Status order = SHIPPED;
    printf("Status code: %d\n", order);

    if (order == SHIPPED) {
        printf("Your order is on the way\n");
    }
    return 0;
}
Output
Status code: 2
Your order is on the way
Run this example on your own computer. The "Get Started" lesson shows how to set it up.

C Enums Practice Exercises

Check what you learned in “C Enums”.

/ 2 solved
Fill in the blank

Declare an enum.

 Level { LOW, MEDIUM, HIGH };
✓ Correct! Not quite. Try again.
Multiple choice

In enum Level { LOW, MEDIUM, HIGH }, what is MEDIUM?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services