O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

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

Constants

Like variables, constants are data storage locations. But variables can vary; constants, on the other hand and as you might have guessed, do not vary.

You must initialize a constant when you create it, and you cannot assign a new value later; after a constant is initialized, its value is, in a word, constant.

Literal Constants

C++ has two types of constants: literal and symbolic.

A literal constant is a value typed directly into your program wherever it is needed. For example:

int myAge = 39;

myAge is a variable, of type int; 39 is ...

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