enums in c with example:
What is the output of below C program?
enum status capState = true;
if(capState == 1)
printf("capSatate is true");
printf("capState is false");
capState is true
capState is false
invalid comparison at if capState==1, we have to compared with only either false or true, else it gives compile time error.
no error, but it crashes at run time.
false is assigned with 0, and true with 1. So we can use integer constants in if condition with an enum. it prints capState is true.
Back To Top