C++ › Const Correctness

What does const mean in C++?

Beginner

Answer

const declares that something won't be modified after initialization. Applied to a variable, it makes it read-only; to a function parameter, it promises not to change the argument; to a member function, it promises not to modify the object. const enables compiler enforcement of immutability, safer interfaces, and certain optimizations.
const int max = 100;   // cannot be reassigned
void print(const std::string& s); // won't modify s
Real-world example Passing a large object by const reference documents and enforces that the function won't change it.

Common follow-ups: What can const be applied to? | How does it help callers?