Data values in a program are usually stored in variables. In C++, if you want to use avariable to hold some information, you must declare that variable before you use it.
Declaring a variable establishes the following properties:
1 • Name. Every variable has a name, which‖ is formed according to the rules described in the section entitled ―Naming conventions later in this chapter. You use the name in the program to refer to the variable and the value it contains.
Type.Each variable in a C++ program is constrained to hold values of a particular data type. C++ includes several predefined types and also allows you to define new types of your own.
2• Lifetime. Depending on how they are declared, some variables persist throughout the entire program, while others are created and destroyed dynamically as the program moves through various levels of function call.
3• Scope. The declaration of a variable also controls what parts of the program have access to the variable, which is called its scope.
The standard syntax for declaring a variable is typenamelist;
int result; int result; result = 0;