What does the const keyword do in C++?
Updated 2026-07-10 · 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.
Common uses
- const variable: a value that cannot change after it is set.
- const reference parameter: pass a large object without copying and without allowing changes.
- const member function: guarantees the method does not modify the object.
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.
Common follow up questions
Related interview questions
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