Programming Languages
C
Objective
Mar 08, 2013
What will be output of the following c code?
void main()
{
enum color{
RED,GREEN=-20,BLUE,YELLOW
};
enum color x;
x=YELLOW;
printf("%d",x);
}
Detailed Explanation
Default value of enum constant = value of previous enum constant +1
Default value of first enum constant=0
Hence:
BLUE=GREEN+1=-20+1=-19
YELLOW=BLUE+1=-19+1=-18
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts