Introduction to Constants

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 ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.