...
In this noncompliant code, pi
is declared as a float
. Although pi is a mathematical constant, its value is not protected from accidental modification.
Code Block | ||||
---|---|---|---|---|
| ||||
float pi = 3.14159f; float degrees; float radians; /* ... */ radians = degrees * pi / 180; |
...
In this compliant solution, pi
is declared as a const
-qualified object.
Code Block | ||||
---|---|---|---|---|
| ||||
const float pi = 3.14159f; float degrees; float radians; /* ... */ radians = degrees * pi / 180; |
...