C Programming Enumeration In this article, you will learn to work with enumeration (enum). Also, you will learn where enums are commonly used in C programming. An enumeration is a user-defined data type that consists of integral constants. To define an enumeration, keyword enum is used. enum flag { const1, const2, ..., constN }; Here, name of the enumeration is flag . And, const1 , const2 ,...., constN are values of type flag . By default, const1 is 0, const2 is 1 and so on. You can change default values of enum elements during declaration (if necessary). // Changing default values of enum enum suit { club = 0, diamonds = 10, hearts = 20, spades = 3, }; Enumerated Type Declaration When you create an enumerated type, only blueprint for the variable is created. Here's how you can create variables of enum type. enum boolean { false, true }; enum boolean check; Here, a variable check of type enum boolean is c
Comments
Post a Comment