const keywordsuggest change
- const Type myVariable = initial; // Declares a const variable; cannot be changed
- const Type &myReference = myVariable; // Declares a reference to a const variable
- const Type *myPointer = &myVariable; // Declares a pointer-to-const. The pointer can change, but the underlying data member cannot be changed through the pointer
- Type * const myPointer = &myVariable; // Declares a const pointer. The pointer cannot be reassigned to point to something else, but the underlying data member can be changed
- const Type * const myPointer = &myVariable; // Declares a const pointer-to-const.
A variable marked as
const cannot be changed. Attempting to call any non-const operations on it will result in a compiler error.
Found a mistake? Have a question or improvement idea? Let me know.
Table Of Contents