Enumerations in C

 Enumerations in C


Enumerations allow you to define a set of named constants with associated values. They provide a convenient way to represent a finite set of values and improve code readability.



#include <stdio.h>


enum Color {

    RED,

    GREEN,

    BLUE

};


int main() {

    enum Color c = GREEN;


    switch (c) {

        case RED:

            printf("Color is red.\n");

            break;

        case GREEN:

            printf("Color is green.\n");

            break;

        case BLUE:

            printf("Color is blue.\n");

            break;

        default:

            printf("Unknown color.\n");

            break;

    }


    return 0;

}

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...