C++ Programming Questions and Answers – Void

This section on C++ language interview questions and answers focuses on “Void”. One shall practice these interview 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++ language interview questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.

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

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
View Answer

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?

advertisement
advertisement
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

Answer: d
Explanation: There are no void objects.
Note: Join free Sanfoundry classes at Telegram or Youtube

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

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?

advertisement
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         void a = 10, b = 10;
  6.         int c;
  7.         c = a + b;
  8.         cout << c;
  9.         return 0;
  10.     }

a) 20
b) compile time error
c) runtime error
d) 40
View Answer

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

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.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.