C++ Questions and Answers Part-13

1. Which of the following will not return a value?
a) null
b) void
c) empty
d) free

Answer: b
Explanation: Because void represents an empty set of values so nothing will be return.

2. ______________ have the return type void.
a) all functions
b) constructors
c) destructors
d) none of the mentioned

Answer: d
Explanation: Constructor creates an Object and Destructor destroys the object. They are not supposed to return anything, not even void.

3. What does the following statement mean?
void a;
a) variable a is of type void
b) a is an object of type void
c) declares a variable with value a
d) flags an error

Answer: d
Explanation: There are no void objects.

4. Choose the incorrect option.
a) void is used when the function does not return a value
b) void is also used when the value of a pointer is null
c) void is used as the base type for pointers to objects of unknown type
d) void is a special fundamental type

Answer: b
Explanation: void fundamental type is used in the cases of a and c.

5. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
void a = 10, b = 10;
int c;
c = a + b;
cout << c;
return 0;
}
a) 20
b) compile time error
c) runtime error
d) 40

Answer: b
Explanation: void will not accept any values to its type.

6. 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
Explanation: Enumerators are used in order to create our own types whereas macros are textual substitutions.

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

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

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

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

9. 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

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

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

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