Chapter 2 C Programming
Chapter 2 C Programming
⚫ Static variable:
⚫ Local variable which exists and retains its value even
after the control is transferred to the calling function
⚫ It is automatically initialized to zero.
⚫ Eg. static int x;
Contd…
⚫ Extern (or) Global variable:
⚫ It is known to all the functions in the file.
⚫ It is automatically initialized to zero.
⚫ Eg. extern int tot;
⚫ Register variable:
⚫ Local variable which is stored in the register
⚫ Eg. register char ch;
Storage class example
⚫ /*Example of storage class*/
int m;
main()
{
int i;
float bal;
……
……
function1();
} function1()
{
int i;
float sum;
……
……
}
⚫ Here the variable m is called the global variable. It can be used
in all the functions in the program.
⚫ The variables bal, sum and i are called local variables.
⚫ Local variables are visible and meaningful only inside the
function in which they are declared.
ASSIGNING VALUES TO VARIABLES
⚫ The syntax is
⚫ Variable_name = constant
Eg:1) int a=20;
2) bal=75.84;
3) yes=’x’;