Home Segments Index Top Previous Next

135: Mainline

Because pi is not only a global variable, but also a mathematical constant, it is best to add const to the definition:

const double pi = 3.14159; 

With the definition marked by const, your C++ compiler should complain if pi ever appears on the left side of an assignment statement.

pi = 3.0  <-- Will not compile; pi is supposed to be a constant