Which statement about the return type of a C++ constructor is correct?

Options

  • A. A constructor must return int
  • B. A constructor must return void
  • C. A constructor has no return type
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. A constructor has no return type

Detailed Explanation

Answer: (C) A constructor has no return type

A C++ constructor does not have a return type.

Unlike an ordinary function, a constructor is specially associated with object initialization. Its name is the same as the class name.

For example:

class Student {
public:
Student() { }
};

Notice that Student() has neither int nor void before its name.

Adding a return type would make it an ordinary member function rather than a constructor.