Constants and immutability
Con.4
Use `const` to define objects with values that do not change after construction
Reason
Prevent surprises from unexpectedly changed object values.
Example
void f()
{
int x = 7;
const int y = 9;
for (;;) {
// ...
}
// ...
}
As x is not const, we must assume that it is modified somewhere in the loop.
Enforcement
- Flag unmodified non-
constvariables.