Which feature of a C++ constructor is used to initialize data members before the constructor body executes?

Options

  • A. Constructor initializer list
  • B. Destructor block
  • C. Namespace declaration
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. Constructor initializer list

Detailed Explanation

Answer: (A) Constructor initializer list

A constructor initializer list is used to initialize data members before the body of the constructor starts executing.

It is especially important for initializing const data members, reference members, and base classes.

Example:

Student(int x) : rollNo(x) { }

Here, rollNo is initialized through the initializer list before the constructor body executes.