Void(C++ Programming ) Questions and Answers

Question 1.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
void a = 10, b = 10;
6.
int c;
7.
c = a + b;
8.
cout
  1.    20
  2.    compile time error
  3.    runtime error
  4.    none of the mentioned
Explanation:-
Answer: Option B. -> compile time error

void will not accept any values to its type.



Question 2.

Choose the incorrect option


  1.    void is used when the function does not return a value.
  2.    void is also used when the value of a pointer is null.
  3.    void is used as the base type for pointers to objects of unknown type.
  4.    void is a special fundamental type.
Explanation:-
Answer: Option B. -> void is also used when the value of a pointer is null.

void fundamental type is used in the cases of a and c.



Question 3.

What does the following statement mean?
 void a;


  1.    variable a is of type void
  2.    a is an object of type void
  3.    declares a variable with value a
  4.    flags an error
Explanation:-
Answer: Option D. -> flags an error

There are no void objects.



Question 4.

____ have the return type void?


  1.    all functions
  2.    constructors
  3.    destructors
  4.    none of the mentioned
Explanation:-
Answer: Option D. -> none of the mentioned

Constructor creats an Object and Destructor destroys the object. They are not supposed to return 

anything, not even void.



Question 5.

Which of the following will not return a value?


  1.    null
  2.    void
  3.    empty
  4.    free
Explanation:-
Answer: Option B. -> void

None.