What is printed by this C code: enum color { RED, GREEN = 5, BLUE }; printf(“%d %d”, RED, BLUE);?
Correct answer A. 0 6
Explanation
Enumeration constants start at 0 unless given a value, so RED is 0. GREEN is explicitly 5, and each constant without an initialiser is one more than the previous one, so BLUE is 6. Answer 0 2 ignores the explicit value given to GREEN. Enumeration constants in C have type int, so they print with %d.
Answer checked How we write and check questions
Discussion