Storage classes in C

• Storage class helps us to define
1. Where to store the variable
2. What is the initial value of variable?
3. How much is the life of a variable?
4. What is the scope of the variable?
• There are 4 storage classes – auto, static, register, and extern.
• auto:
o An auto variable is created each time the block in which it is declared is entered and is destroyed each time the block is exited.
o Such variable can be declared only in functions.
o By default, a local variable is auto but it can be declared to be of another storage class by the use of explicit storage class in its declaration.
o A function cannot be declared as auto.

• static
o These variables remain in existence throughout the execution of the program.
o Global and local variables can be declared as static but not formal arguments.
o When a global variable or function is declared explicitly to be static, its scope is restricted to the file in which it is declared.
• register
o A local variable or formal parameter can be declared to be register.
o Here declaration means to store the variable in a machine register instead of the main memory.
o It is like auto variable since it disappears when the function exists.
o The only restriction is that a register variable must be of a type whose size is not longer than the size of a register.
o The address of register cannot be taken and hence & operator may not be used.
o A function of global variable cannot be declared as register.
• extern
o This storage class does not allocate any memory for a variable but declares it to have been created elsewhere in the program.
o This declaration must be used to access a global variable declared in another file in which it may be used in either global or local declaration.
o A formal parameter cannot be extern.
o A function is by default extern although this storage class needs never to be used in a function definition declaration.


Related Links :

No comments:

Post a Comment


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!