what is variable?

 


what is variable?

    Variable is the memory location where constants are stored. Variable is an entity which can hold one or more values. These values are may be number or character.

Example:- a=10;

In the above example "a" is called variable that stores value"10" in its memory location.

Rules of naming variable    

  • A variable must be an alphabet.(a-z)
  • That alphabet always be lower case.
  • A variable can declare using number or underscore.             
  • There is no space between any variable.
  • Comma operator is used to separate between two variables.
Variable is classified as two types:
  1. Local Variable
  2. Global Variable
Local Variable
    In this case variables are declare within a particular block of function.

    main( )
    {
        int x;
                sum( );
                mul( );
    }
                 sum( )
              {
                int a,b;
                ---------
                ---------
                }
                mul( )
                {
                int m,n;
                ---------
                ---------
    }
Global variable
    In this case variables are declare outside the function.

int sum;
main( )
{
        int a,b;
        add;
        printf("%d",sum);
        }
        add()
        {
        int a,b;
        sum=s+b;
        printf("%d",sum);
}
    
    
 

No comments: