What is the difference between following 2 enum declarations in C ?
-
typedef enum colour
{ Red, Blue
}; -
typedef enum colour//in your response please refer to this colour as colour2 to avoid confusion
{ Red,Blue
}colour;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the simplest case, an enumeration can be declared as
Any references to this must be preceded with the enum keyword. For example:
In order to avoid having to use the enum keyword everywhere, a typedef can be created:
With typedef, The same variablea can be now declared as
FYI, structures in C also follows the similar rules. typedef also makes your code look neater without the C struct(enum) keywords. It can also give logical meanings.