250+ TOP MCQs on Enumerations and Answers

This section on online C++ test on “Enumerations”. One shall practice these test questions to improve their C++ programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C online test questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.Here is a listing of online C++ test questions on “Enumerations” along with answers, explanations and/or solutions:

1. Identify the incorrect option.
a) enumerators are constants
b) enumerators are user-defined types
c) enumerators are same as macros
d) enumerator values start from 0 by default

Answer: c
Clarification: Enumerators are used in order to create our own types whereas macros are textual substitutions.

2. In which type do the enumerators are stored by the compiler?
a) string
b) integer
c) float
d) string & float

Answer: b
Clarification: In C++, enumerations are stored as integers by the compiler starting with 0.

3. To which of these enumerators can be assigned?
a) integer
b) negative
c) enumerator
d) all of the mentioned

Answer: d
Clarification: Since enumerators evaluate to integers, and integers can be assigned to enumerators, enumerators can be assigned to other enumerators.

4. What will happen when defining the enumerated type?
a) it will not allocate memory
b) it will allocate memory
c) it will not allocate memory to its variables
d) allocate memory to objects

  250+ TOP MCQs on Pointer to Void and Answers

Answer: a
Clarification: Enumerator will allocate the memory when its variables are defined.

5. Which variable does equals in size with enum variable?
a) int variable
b) float variable
c) string variable
d) float & string variable

Answer: a
Clarification: The enum variable is converted to an integer and stored by the compiler. So both are equal in size.

6. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     enum  cat
  4.     {
  5.         temp = 7
  6.     };
  7.     int main()
  8.     {
  9.         int age = 14;
  10.         age /= temp;
  11.         cout << "If you were cat, you would be " << age << endl;
  12.         return 0;
  13.     }

a) If you were cat, you would be 5
b) If you were cat, you would be 2
c) If you were cat, you would be 7
d) If you were cat, you would be 9

Answer: b
Clarification: 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

7. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     enum test
  4.     {
  5.         A = 32, B, C
  6.     };
  7.     int main()
  8.     {
  9.         cout << A << B<< C;
  10.         return 0;
  11.     }

a) 323334
b) 323232
c) 323130
d) 323134

Answer: a
Clarification: 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

8. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     enum colour
  4.     {
  5.         green, red, blue, white, yellow, pink
  6.     };
  7.     int main()
  8.     {
  9.         cout << green<< red<< blue<< white<< yellow<< pink;
  10.         return 0;
  11.     }

a) 012345
b) 123456
c) compile time error
d) runtime error

9. What will be the output of the following C++ code?

  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 <= zee; i++)
  9.         {
  10.             printf("%d ", i);
  11.         }
  12.         return 0;
  13.     }

a) 012
b) 123
c) compile time error
d) runtime error

Answer: c
Clarification: Enumeration variable ‘star’ appears two times in main() which causes the error. An enumaration constant must be unique within the scope.

10. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int i;
  6.         enum month
  7.         {
  8.             JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
  9.         };
  10.         for (i = MAR; i <= NOV; i++)
  11.             cout << i;
  12.         return 0;
  13.     }

a) 01234567891011
b) 123456789101112
c) 34567891011
d) 123456789

Answer: c
Clarification: We are getting the values from march to november and printing its concern number.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top