Chapter 2

Declaring Variables Constantly

In This Chapter

arrow Declaring variables

arrow Declaring different types of variables

arrow Using floating-point variables

arrow Declaring and using other variable types

The most fundamental of all concepts in C++ is the variable — a variable is like a small box. You can store things in the box for later use, particularly numbers. The concept of a variable is borrowed from mathematics. A statement such as

  x = 1

stores the value 1 in the variable x. From that point forward, the mathematician can use the variable x in place of the constant 1 — until he changes the value of x to something else.

Variables work the same way in C++. You can make the assignment

  x = 1;

From that point forward in the execution of the program, the value of x is 1 until the program changes the value to something else. References to x are replaced by the value 1. In this chapter, you will find out how to declare and initialize variables in C++ programs. You will also see the different types of variables that C++ defines and when to use each.

Declaring Variables

A mathematician might write ...

Get C++ For Dummies, 7th Edition now with the O’Reilly learning platform.

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