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
View Answer
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
View Answer
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
View Answer
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
View Answer
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
View Answer
Explanation: void will not accept any values to its type.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for C++ Internship
- Check Computer Science Books
- Check C++ Books
- Apply for Computer Science Internship
- Check Programming Books