C Programming Tutorial 0/65 lessons ~6 min read Lesson 36

    Enumeration (enum)

    enum defines named integer constants — improves readability over raw numbers.

    Course progress0%
    Focus
    10 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    enum defines named integer constants — improves readability over raw numbers.

    Understanding the topic

    Default values Start at 0 unless specified.

    Custom values enum { A = 1, B = 5, C = 6 };

    • Default values — Start at 0 unless specified.
    • Custom values — enum { A = 1, B = 5, C = 6 };.

    Step-by-step explanation

    1. Default values — Start at 0 unless specified.
    2. Custom values — enum { A = 1, B = 5, C = 6 };.

    Syntax reference

    Syntax reference:

    c
    enum Name { IDENT = value, ... };

    Informative example

    Example program:

    c
    #include <stdio.h>
    enum Day { MON, TUE, WED };
    int main(void) {
    enum Day d = WED;
    printf("%d\n", d);
    return 0;
    }

    Output

    2

    Execution workflow

    1Enumeration (enum) — step by step
    1 / 2

    Default values

    Start at 0 unless specified.

    Best practices

    • Enable warnings: gcc -Wall -Wextra -std=c11 source.c -o app
    • Give every variable a defined value before it is read.
    • Stay inside array bounds — C will not stop you from over-running a buffer.

    Common mistakes

    • Reading uninitialized storage — behavior is undefined.
    • Dismissing compiler warnings instead of fixing root causes.
    • Ignoring NULL returns from malloc, fopen, and similar APIs.

    Hands-on exercise

    Practice problems:

    • enum for menu choices
    • Switch on enum value

    Summary

    Enumeration (enum) in C — Readable names for integral constants.

    Ready to mark this lesson complete?Track your journey across the entire course.