0
What is the use of enum keyword ?
I know what it is and how it works but what is the use of this keyword
4 Respuestas
0
If you don't want to use a macro, but actually want to define an array of macros, enums are useful. The values of enums will be automatically defined (incremental values) , so you don't have to define a value for each enum, unlike macro. Also enums can be a type definition so you can actually try to restrict the value of a parameter inside a function.
0
will you please give an example illustrating what you said. Thanks
0
Like this
typedef enum cardsuit {
Clubs = 5,
Diamonds,
Hearts,
Spades
};
cardsuit myCards;
I defined a type of an enum and used it as a variable. So you can use it in a for example if clause.
if (myCards == Clubs)
....
Also I started Clubs from 5, so next enums continue with the number 6 and increments accordingly. I didn't define it as a macro.
0
thanks for your help buddy !