C Academy · Lesson

Enumerations (enum)

Discover how enumerations improve code readability and efficiency.

Lesson 3 of 310 steps

Enumerations (enum) is a free C Academy lesson on CoddyKit. This is lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, and your progress syncs across the web and the CoddyKit app. The C Academy course includes 3 lessons in total.

Enumerations in C

An enumeration (enum) is a user-defined data type that assigns names to a set of integer values.

In this lesson, you will learn:

  • How to define and use enumerations.
  • How enum improves code readability.
  • How to assign custom values to enumeration constants.
Enumerations (enum) — illustration 1

What is an Enumeration?

Enumerations assign names to a set of integer constants.

Example declaration:

enum Color {RED, GREEN, BLUE};

By default, RED is 0, GREEN is 1, and BLUE is 2.

Using an Enumeration

Once defined, enum can be used as a variable type:

enum Color myColor; myColor = GREEN;

Now, myColor holds the value 1.

Example: Using Enumeration

This program demonstrates how to define and use an enumeration.

#include <stdio.h>

enum Color {RED, GREEN, BLUE};

int main() {
    enum Color myColor = GREEN;
    printf("Selected color: %d\n", myColor);
    return 0;
}

Assigning Custom Values

You can assign specific values to enum constants:

enum Status {SUCCESS = 1, FAILURE = 0};

Now, SUCCESS is 1 and FAILURE is 0.

Example: Custom Values in Enum

This program demonstrates assigning custom values in an enum.

#include <stdio.h>

enum Status {SUCCESS = 1, FAILURE = 0};

int main() {
    enum Status result = SUCCESS;
    printf("Operation result: %d\n", result);
    return 0;
}

Enum with Incremental Values

By default, enum values increase by 1 unless explicitly assigned:

enum Days {SUN = 1, MON, TUE, WED};

Here, MON is 2, TUE is 3, and so on.

Advantages of Using Enumerations

Enumerations improve code readability and maintainability:

  • They replace hard-coded numbers with meaningful names.
  • They prevent accidental assignment of invalid values.
  • They make debugging easier.

Summary

In this lesson, you learned:

  • How to define and use enumerations.
  • How to assign custom values to enum constants.
  • How enum improves code readability and efficiency.

Next, we will explore file handling in C!

Enumerations (enum) — illustration 10
Free to start

Learn C with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
39
Lessons
144

Frequently Asked Questions

Is the “Enumerations (enum)” lesson free?

Yes — the full text of “Enumerations (enum)” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO. The C Academy course includes 3 lessons in total.

What will I learn in “Enumerations (enum)”?

Discover how enumerations improve code readability and efficiency. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start C Academy?

No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 3.

How long does the “Enumerations (enum)” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this C Academy lesson?

Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Defining and Using Structures
  2. Unions and Memory Efficiency
  3. Enumerations (enum)
← Back to C Academy