const keyword:
const keyword
suggest changeSyntax
- 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
10const keyword
11Loops
14keywords
17Pointers
26std::map
29std::any
38File I/O
39Streams
51Unions
56Lambdas
60SFINAE
62RAII
67Sorting
84RTTI
87Scopes
102Attributes
104Profiling
107Recursion
113Header files
117Iteration
125Alignment
133Optimization
134Semaphore
136Debugging
139Mutexes
141Unit testing
142decltype
146Contributors