What will be the output of the following C code? [code]#include<stdio.h> enum colour { blue, red, yellow }; main() { enum colour

What will be the output of the following C code?
Code:
#include<stdio.h>
enum colour
{
    blue, red, yellow
};
main()
{
    enum colour c;
    c=yellow;
    printf("%d",c);
}
A. 1
B. 2
C. 0
D. Error
 
Answer: c
Explanation: Enum variables are automatically assigned values if no value is specified. The compiler by default assigns values starting from 0. Therefore, in the above code, blue gets 0, red gets 1 and yellow gets 2.
 

Tìm kiếm

Back
Top