C++ Interview Question

What does the const keyword do in C++?

Updated 2026-08-16 · Beginner friendly
Quick answer

The const keyword marks something as unchangeable. A const variable cannot be reassigned, a const parameter cannot be modified inside a function, and a const member function promises not to change the object's data. Using const clearly communicates intent and lets the compiler catch accidental changes.

Key takeaways
  • const marks something as unchangeable, catching accidental modification at compile time.
  • It applies to variables, parameters, and member functions that promise not to change the object.
  • Passing large objects by const reference avoids a copy while preventing modification.

Common uses

const int MAX = 100;              // cannot change
void print(const std::string& s); // no copy, no modification
int getvalue() const;             // does not change the object
In the interview

A strong point is const correctness: use const wherever a value should not change so the compiler enforces it. Passing large objects by const reference is a classic tip that shows you care about both safety and performance.

Frequently asked questions

What is const correctness?

It is the practice of using const wherever a value should not change, so the compiler enforces it and the code clearly communicates intent.

What is the difference between const and constexpr?

const means the value does not change after initialisation, while constexpr means the value is computed at compile time and is a true constant expression.

Want the full C++ guide?

Read every C++ concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the C++ guide All C++ questions