An entity that may very during the program execution is known as variable .Variable are the name given location in a memory .rules are

1.  Length is must be 1-31 character

2.  Only alphabet digit & underscore is used.

3.  First character must be an alphabet or an underscore

4.  Name can’t start with digit

5.  Keywords can’t be used

6.  Space & symbol are not allowed

7.  Upper case and lower case are different

 

Variable Definition in C++ 

A variable definition tells the compiler where and how much storage to create for the variable. A variable definition specifies a data type, and contains a list of one or more variables of that type as follows:

type variable_list;


Local Variables 

Variables that are declared inside a function or block are local variables. They can be used only by statements that are inside that function or block of code. Local variables are not known to functions outside their own.

int main (){

// Local variable declaration:

int a, b;

int c;

            }

 

Global Variables 

Global variables are defined outside of all the functions, usually on top of the program. The global variables will hold their value throughout the life-time of your program.

int g;  //global variables

int main (){

// Local variable declaration:

int a, b;

            }

 

Example of Variable

#include<iostream.h>

#include<conio.h>

void main(){

            int i;       

            clrscr();

            cout<<"Enter a value of i:";

            cin>>i;

            cout<<i;

getch();

}

Output

        Enter value of I = 56

        56