Variables

C++ would be of limited use if you could not use it to store the results of calculations, whether in memory or in a disk file. Variables allow you to give names to areas of memory for storing such results. Variables in C++ have definite types, such as int, double, etc., and more complex types that are built from these basic types.

Declarations

A declaration is a statement that sets aside some space in memory. It consists of a type, followed by a list of variables. A variable can contain a value, and you often set this value when you are declaring the variable. For example, the following declaration defines a variable k of type int, and it allocates 4 bytes for it:

;> int k  = 10;
						

After a variable has been defined, you can use it in ...

Get C++ By Example: UnderC Learning Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.