A storage class represents the visibility and a location of a variable. It tells from what part of code we can access a variable. A storage class in C is used to describe the following things:
- The variable scope.
- The location where the variable will be stored.
- The initialized value of a variable.
- A lifetime of a variable.
- Who can access a variable?
Thus a storage class is used to represent the information about a variable.
NOTE: A variable is not only associated with a data type, its value but also a storage class.
There are total four types of standard storage classes. The table below represents the storage classes in C.
Storage class | Purpose |
auto | It is a default storage class. |
extern | It is a global variable. |
static | It is a local variable which is capable of returning a value even when control is transferred to the function call. |
register | It is a variable which is stored inside a Register. |
Different types of storage classes in C with examples-
- Auto Storage Class in C
- Extern Storage Class in C
- First File: main.c
- Second File: original.c
- Static Storage Class in C
- Register Storage Class in C