O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required