What is the purpose of a const member function in C++?

Options

  • A. It guarantees that the function will never be called
  • B. It allows the function to modify every data member
  • C. It promises not to modify the object's non-mutable data members
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. It promises not to modify the object's non-mutable data members

Detailed Explanation

Correct Answer: Option C

Explanation:
A const member function is declared by placing const after its parameter list, such as int getValue() const. It cannot normally modify the object's non-mutable data members. The const qualifier also allows the function to be called on const objects.