October 2004
Beginner
408 pages
9h 24m
English
The final data type introduced in this chapter is the constant. Unlike a variable, whose value can change over the course of an application, a constant's value never changes once it's been set. Still, you work with a constant much as you would a variable.
Constants, like variables, are of a certain type, like int or char. To declare a constant, start with the keyword const, followed by the type and name:
const type NAME;
const float TAXRATE;
const char RIGHT_ANSWER;
Although it's not required, it's commonplace to name constants using all uppercase letters as you see in these examples. Otherwise, the naming rules for constants are the same as those for variables.
After declaring a constant, assign a value as you would ...
Read now
Unlock full access