Sail E0 Webinar

MCQs

Total Questions : 10
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
  1.    01234567891011
  2.    123456789101112
  3.    34567891011
  4.    123456789
 Discuss Question
Answer: Option C. -> 34567891011

we are getting the values from march to november and printing its concern number.


Question 2.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
enum colour {
4.
green, red, blue, white, yellow, pink
5.
};
6.
int main()
7.
{
8.
cout
  1.    012345
  2.    123456
  3.    compile time error
  4.    runtime error
 Discuss Question
Answer: Option A. -> 012345

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
  1.    012
  2.    123
  3.    compile time error
  4.    runtime error
 Discuss Question
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
  1.    323334
  2.    323232
  3.    323130
  4.    none of the mentioned
 Discuss Question
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
  1.    If you were cat, you would be 5
  2.    If you were cat, you would be 2
  3.    If you were cat, you would be 7
  4.    none of the mentioned
 Discuss Question
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?


  1.    int variable
  2.    float variable
  3.    string variable
  4.    none of the mentioned
 Discuss Question
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?


  1.    it will not allocate memory
  2.    it will allocate memory
  3.    it will not allocate memory to its variables
  4.    none of the mentioned
 Discuss Question
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?


  1.    integer
  2.    negative
  3.    enumerator
  4.    all of the mentioned
 Discuss Question
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?


  1.    string
  2.    integer
  3.    float
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> integer

None.


Question 10.

Identify the incorrect option.


  1.    enumerators are constants
  2.    enumerators are user defined types
  3.    enumerators are same as macros
  4.    enumerator values start from 0 by default
 Discuss Question
Answer: Option C. -> enumerators are same as macros

enumerators are used in order to create our own types whereas macros are textual substitutions.


Latest Videos

Latest Test Papers