About Me

Hello there! Before talking about qualifications and professional abilities, I would like to introduce myself. I am a Yuvraj Basnet and professional software developer and have been working in this field for 3 long years. I have finished my graduation from The University of Delhi on Computer Science Engineering I considered myself a reasonably experienced programmer with a particular interest in the human side of software development, computers are fascinating machine, but they're mostly reflection of the people using them. In the art of software development, studying code isn't enough; you have to study the people behind the software, too.


In this tutorial you will learn most important term of c programming i.e, storages classes with examples.

I will also provide a link to easily understand the storage classes. 


                                           STORAGE CLASSES

A storage class defines the scope (visibility) and life-time of variables and/or functions within a C Program. They precede the type that they modify.
We have four different storage classes in a C program: 

1) auto storage classes.
2) register storage classes.
3) static storage classes. 
4) extern storage classes.

Image result for storage classes in c

The auto storage class is the default storage class for all local variables.

 int mount; 
 auto int month;

 The example above defines two variables within the same storage class. ‘auto’ can only be used within functions, i.e., local variables.

The register storage class is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size (usually one word) and can't have the unary '&' operator applied to it (as it does not have a memory location).

 register int miles;

This storage class is used to declare static variables which are popularly used while writing programs in C language. Static variables have a property of preserving their value even after they are out of their scope! Hence, static variables preserve the value of their last use in their scope. So we can say that they are initialized only once and exist till the termination of the program. Thus, no new memory is allocated because they are not re-declared. Their scope is local to the function to which they were defined. Global static variables can be accessed anywhere in the program. By default, they are assigned the value 0 by the compiler.

void test()
    static int a
= 0;       //a static variable
= a + 1;

Extern storage class simply tells us that the variable is defined elsewhere and not within the same block where it is used. Basically, the value is assigned to it in a different block and this can be overwritten/changed in a different block as well. So an extern variable is nothing but a global variable initialized with a legal value where it is declared in order to be used elsewhere. It can be accessed within any function/block.

int main()
    extern int x
;   //informs the compiler that it is defined somewhere else
= 10;     
printf("%d", x);    } CLICK HERE, To watch the video of described 4 storage classes of the c - auto, register, extern, static. All storage classes defines the storing place, scope and lifetime for the variable.


Post a Comment