#include <stdio.h>
enum {AA, BB, CC} s;
int main()
{
s = 4;
printf("%d\n",s);
return 0;
}
The compiler doesn’t give any warning and prints 4. What is happening behind the scene? Is s treated as an int type?
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.
The specific type of an enumeration is implementation specific, but it is often an
int. So yes, in this casesis probably anint. From the C spec:So in your case, 4 will certainly work, since it fits in a
charand in any signed or unsigned integer type on any machine I’ve ever heard of.