Here is a listing of C++ language interview questions on “Void” along with answers, explanations and/or solutions:
1. Which of the following will not return a value?
a) null
b) void
c) empty
d) free
Answer: b
Clarification: 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
Clarification: 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?
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
Clarification: 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
Clarification: void fundamental type is used in the cases of a and c.
5. What will be the output of the following C++ code?
-
#include
-
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
Clarification: void will not accept any values to its type.