Saturday, May 9, 2009

Enum data type?

enum color {pink,blue};


enum color c;


why should we declare a variable of enum color as


enum color c;//stmnt1


and not as


color c;//stmnt 2


why is "enum" word required to declare a variable "c" of type


color? we already know that "color" is of enum type.


what was the purpose of choosing to keep stmnt1 over stmnt2


by the compiler designers?

Enum data type?
Depends on the language. In C#, C++. color c is perfectly valid.





In C, not so much. They work much like structures, which must be declared in the same way. With the move towards more readable code and OOP, it seems silly to declare variables with the enum keyword twice.


No comments:

Post a Comment