Enumerations(C++ Programming ) Questions and Answers
Question 1.
What is output of the this program?
1. #include 2. using namespace std; 3. int main() 4. { 5. int i; 6. enum month { 7. JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC 8. }; 9. for (i = MAR; i
01234567891011
123456789101112
34567891011
123456789
Explanation:-
Answer: Option C. -> 34567891011
we are getting the values from march to november and printing its concern number.
The enumerator values start from zero if it is unassigned. Output: $ g++ enum3.cpp $ a.out 012345
Question 3.
What is the output of this program?
1. #include 2. using namespace std; 3. int main() 4. { 5. enum channel {star, sony, zee}; 6. enum symbol {hash, star}; 7. int i = 0; 8. for (i = star; i
012
123
compile time error
runtime error
Explanation:-
Answer: Option C. -> compile time error
enumartion variable 'star' appears two times in main() which causes the error. An enumaration
constant must be unique within the scope.
Question 4.
What is the output of this program?
1. #include 2. using namespace std; 3. enum test { 4. A = 32, B, C 5. }; 6. int main() 7. { 8. cout
323334
323232
323130
none of the mentioned
Explanation:-
Answer: Option A. -> 323334
If we not assigned any value to enum variable means, then the next number to initialized number will
be allocated to the variable. Output: $ g++ enum2.cpp $ a.out 323334
Question 5.
What is the output of this program?
1. #include 2. using namespace std; 3. enum cat { 4. temp = 7 5. }; 6. int main() 7. { 8. int age = 14; 9. age /= temp; 10. cout
If you were cat, you would be 5
If you were cat, you would be 2
If you were cat, you would be 7
none of the mentioned
Explanation:-
Answer: Option B. -> If you were cat, you would be 2
The age will be divided by using compound assignment operator and so it will return the age of the
cat according to your age. $ g++ enum1.cpp $ a.out If you were cat, you would be 2
Question 6.
Which variable does equals in size with enum variable?
int variable
float variable
string variable
none of the mentioned
Explanation:-
Answer: Option A. -> int variable
The enum variable are converted to integer and stored by compiler. So both are equal in size.
Question 7.
What will happen when defining the enumerated type?
it will not allocate memory
it will allocate memory
it will not allocate memory to its variables
none of the mentioned
Explanation:-
Answer: Option A. -> it will not allocate memory
Enumerator will allocate the memory when its variables are defined.
Question 8.
To which of these enumerators can be assigned?
integer
negative
enumerator
all of the mentioned
Explanation:-
Answer: Option D. -> all of the mentioned
Since enumerators evaluate to integers, and integers can be assigned to enumerators, enumerators
can be assigned to other enumerators.
Question 9.
In which type does the enumerators are stored by the compiler?
string
integer
float
none of the mentioned
Explanation:-
Answer: Option B. -> integer
None.
Question 10.
Identify the incorrect option.
enumerators are constants
enumerators are user defined types
enumerators are same as macros
enumerator values start from 0 by default
Explanation:-
Answer: Option C. -> enumerators are same as macros
enumerators are used in order to create our own types whereas macros are textual substitutions.