Every variable in C programming has two properties: type and storage class. Type refers to the data type of a variable. And, storage class determines the scope, visibility and lifetime of a variable.
Storage Classes are used to describe the features of a variable/function. These features basically include the scope, visibility and life-time which help us to trace the existence of a particular variable during the runtime of a program.
- scope –
Where the value of the variable would be available inside a program. - default initial value –
Its default initial value. - lifetime of that variable –
For how long will that variable exist.
Types of Storage Classes :
There are 4 types of storage class: automatic, external, static, and register. These are explained as following below.

- Automatic storage class :
This is the default storage class for all the variables declared inside a function or a block. Hence, the keyword auto is rarely used while writing programs in C language. The auto storage class is the default storage class for all local variables. It uses “auto” keyword to represent in Automatic storage class.{ int year; auto int year; } - External storage class :
External storage class simply tells us that the variable is defined elsewhere and not within the same block where it is used. It uses “extern” keyword to represent in Automatic storage class.{ int year; extern int year; } - Static storage class :
Static variable retains its value between multiple function calls or recursion calls. It uses “static” keyword to represent in Automatic storage class.{ int year; static int year; } - Register storage class :
Register storage class declares register variables which have the same functionality as that of the auto variables, but it stores in register of microprocessor. Program runs faster using this storage class. It uses “register” keyword to represent in Automatic storage class.{ int year; register int year; }
There is brief comparison between these storage classes :
| Property | Automatic | External | Static | Register |
|---|---|---|---|---|
| Declaration | Inside a function/block | Outside all functions | Inside or outside function | Inside a function/block |
| Storage | Stack | Memory | Memory | Memory |
| Default Value | Garbage | 0 | 0 | Garbage |
| Scope | Local | Global | Local | Local |
| Life | End of block | Till end of program | Till end of program | End of program |
Please write comments if you find anything incorrect. A gentle request to share this topic on your social media profile.
