Difficulty: Easy
Correct Answer: 0..1..2
Explanation:
Introduction / Context:
This question tests knowledge of how enumeration constants are assigned integer values in C when explicit values are not provided. Enumerations are a convenient way to assign symbolic names to integer constants, and by default they start from zero and increase by one for each subsequent identifier.
Given Data / Assumptions:
Concept / Approach:
In C, if the first enumerator in an enum definition is not given an explicit value, it is assigned the integer value zero. Each subsequent enumerator that is also not given a value is assigned the previous value plus one. Therefore, in enum colors { BLACK, BLUE, GREEN }, the value of BLACK is zero, BLUE is one, and GREEN is two. The printf call prints these integer values separated by two dots.
Step-by-Step Solution:
Step 1: Determine the value of BLACK. As the first enumerator without an explicit value, BLACK is zero.Step 2: Determine the value of BLUE. Since no explicit value is given, BLUE is one more than BLACK, so BLUE is one.Step 3: Determine the value of GREEN. It is one more than BLUE, so GREEN is two.Step 4: The printf statement prints BLACK, BLUE, and GREEN in order with format "%d..%d..%d".Step 5: Substituting the values, the output is 0..1..2.
Verification / Alternative check:
Compiling and running this program with a standard C compiler prints 0..1..2 as expected. You can also change the enum to give BLACK an explicit value such as ten and observe that BLUE and GREEN automatically become eleven and twelve, which confirms the incrementing behaviour.
Why Other Options Are Wrong:
Option A, 1..2..3, would be correct only if the enumeration started at one instead of zero.Option C, 1..1..1, would require all three identifiers to have the same value, which is not the default rule.Option D, 0..0..0, would require that none of the identifiers increment, which also does not follow the C standard.
Common Pitfalls:
Some learners forget that enumerations default to starting at zero and mistakenly assume they start at one. Others think that enumerations are completely separate from integers, but in C they are closely related and can be printed with integer format specifiers. Remember the default starting value and the simple increment rule for unnamed values.
Final Answer:
The correct answer is 0..1..2.
Discussion & Comments