1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. What does the trailing const in double area() const…

Added 30 Nov -0001

What does the trailing const in double area() const; promise in C++?

  1. The function returns a constant value
  2. The function may only be called once per object
  3. The object is copied before the call is made
  4. The function cannot modify the object's members Correct answer

Correct answer

D. The function cannot modify the object's members

16 views

MCQSEXAM

Explanation

A const member function treats this as a pointer to const, so member variables cannot be assigned inside it unless they are marked mutable. The promise matters because it allows the function to be called on const objects and const references, which is why accessors such as getters are declared const. Trying to modify a member in such a function is a compile-time error, not a run-time check.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C++ and Object-Oriented Programming MCQs

Practise all C++ and Object-Oriented Programming MCQs

Similar MCQs