'''Const correctness''' is a programming language feature that allows the programmer to indicate when an object can and cannot change. This can be used to improve [[encapsulation]], itscorrectness, mostand famouseven implementorperformance. beingThe best known language with this feature is [[C plus plus programming language|C++]]. In languages supporting this feature, variables can be saiddeclared to beas 'const'. When a const object is referencedused, only the methodscompiler declaredwill asdo constits maybest beto prevent the object from being calledchanged. This allows programmers to formalise a specificsimple form of [[design by contract|design contract]]: they can promise at compile-time that a parameter of a function cannot be modified destructively.
OfA course,[[class method]] can be declared as const, indicating that calling that method does not change the object. Const methods can only call other const methods, andbut cannot assign [[field (computer science)|member variables]]. (In C++, a member variable can be declared as <code>mutable</code>, indicating that a const method can change its value. This can be used for [[cache|caching]] and [[reference counting]], where the meaning of the object is unchanged, but the object is not [[bitwise const]].)
In C++, a member variable declared with the ''mutable'' keyword can be modified when the method or even the entire class is const. This can be used to maintain internal data that needs to change even in const objects, such as in [[Reference counting|reference counting]] and [[cache|caching]].