Constants

a locked box where we can't put new things inside

const Type Qualifier

According to cppreference, const is a type of qualifier in C, adding a "quality" of being constant to the "variable". A variable with such a qualifier in front is not allowed to be reassigned.

const double PI = 3.141592654;

Typically, we name constants using the UPPER_SNAKE_CASE convention, which is discussed below.

Superficially, this protects unchangeable variables from changing, by emitting an error during compilation, making it safer. But on a deeper level, this qualifier can change the program to a lower, more technical level in the compiler, possibly altering performance and space efficiency.

Last updated