assumed as auto and stored in the memory. When a variable is declared as register, it is stored
in the CPU registers. The default value of the variable will be garbage value. Scope of the
variable within the block where it is defined and the life of the variables is until the control
remains within the block.
Register variable has faster access than normal variable. Frequently used variables are kept in
register. Only few variables can be placed inside register.
NOTE : We can't get the address of register variable
Sytax : register data_type variable_name;
Ex: register int i;
Ex : void demo(); OUTPUT
void main() 20
{ 20
demo(); 20
demo();
demo();
}
void demo()
{
register int i=20;
printf(“%d\n”,i);
i++;
}
3 : Static Storage class : When a variable is declared as static, it is stored in the memory. The
default value of the variable will be zero. Scope of the variable is within the block where it is
defined and the life of the variable persists between different function calls. To define a variable
as static storage class, the keyword „static‟ is used. A static variable can be initialized only
once, it cannot be reinitialized.
Syntax : static data_type variable_name;
C PROGRAMMING Page 161
, Ex: static int i;
Ex : void demo(); OUTPUT
void main() 20
{ 21
demo(); 22
demo();
demo();
}
void demo()
{
static int i=20;
printf(“%d”,i);
i++;
}
4 : External Storage class : When a variable is declared as extern, it is stored in the memory.
The default value is initialized to zero. The scope of the variable is global and the life of the
variable is until the program execution comes to an end. To define a variable as external storage
class, the keyword „extern‟ is used. An extern variable is also called as a global variable.
Global variables remain available throughout the entire program. One important thing to
remember about global variable is that their values can be changed by any function in the
program.
Systax : extern data_type variable_name;
extern int i;
Ex:
C PROGRAMMING Page 162
, int number;
void main()
{
number=10;
}
fun1()
{
number=20;
}
fun2()
{
number=30;
}
Here the global variable number is available to all three functions.
Ex : void fun1();
void fun2();
int e=20;
void main()
{
fun1();
fun2();
}
void fun1()
C PROGRAMMING Page 163
in the CPU registers. The default value of the variable will be garbage value. Scope of the
variable within the block where it is defined and the life of the variables is until the control
remains within the block.
Register variable has faster access than normal variable. Frequently used variables are kept in
register. Only few variables can be placed inside register.
NOTE : We can't get the address of register variable
Sytax : register data_type variable_name;
Ex: register int i;
Ex : void demo(); OUTPUT
void main() 20
{ 20
demo(); 20
demo();
demo();
}
void demo()
{
register int i=20;
printf(“%d\n”,i);
i++;
}
3 : Static Storage class : When a variable is declared as static, it is stored in the memory. The
default value of the variable will be zero. Scope of the variable is within the block where it is
defined and the life of the variable persists between different function calls. To define a variable
as static storage class, the keyword „static‟ is used. A static variable can be initialized only
once, it cannot be reinitialized.
Syntax : static data_type variable_name;
C PROGRAMMING Page 161
, Ex: static int i;
Ex : void demo(); OUTPUT
void main() 20
{ 21
demo(); 22
demo();
demo();
}
void demo()
{
static int i=20;
printf(“%d”,i);
i++;
}
4 : External Storage class : When a variable is declared as extern, it is stored in the memory.
The default value is initialized to zero. The scope of the variable is global and the life of the
variable is until the program execution comes to an end. To define a variable as external storage
class, the keyword „extern‟ is used. An extern variable is also called as a global variable.
Global variables remain available throughout the entire program. One important thing to
remember about global variable is that their values can be changed by any function in the
program.
Systax : extern data_type variable_name;
extern int i;
Ex:
C PROGRAMMING Page 162
, int number;
void main()
{
number=10;
}
fun1()
{
number=20;
}
fun2()
{
number=30;
}
Here the global variable number is available to all three functions.
Ex : void fun1();
void fun2();
int e=20;
void main()
{
fun1();
fun2();
}
void fun1()
C PROGRAMMING Page 163