constcorrectness
Const correctness is a design principle in programming, especially in C and C++, that requires code to respect immutability guarantees conveyed by const qualifiers. Declaring data as const and marking functions as const when they do not mutate their object helps the compiler enforce immutability, catch unintended side effects, and improve code reliability. It also enables potential optimizations by allowing the compiler to assume that certain data will not change.
The concept involves several interrelated ideas. Top-level const vs low-level const distinguishes whether the object or
Common examples include: void print(const std::string& s); which guarantees s will not be changed, or int getValue()
Pitfalls include using const_cast to remove constness, which is only safe if the original object was not