Contents
Storage Classes?
The storage class of a variable or function determines where and how the variable or function is stored in memory and how other parts of the program can access it. The storage classes in C language are stack, heaps, and the main memory. Each has different characteristics and applications. Understanding how to use the storage classes in C gives a programmer maximum control over his system’s memory usage. Plus, implementing a well-thought-out memory management scheme can improve a program’s performance and stability. In this article we are going to explore storage classes in C programming.
There are Four Types of Storage Class in C
- Automatic Storage Class
- Register Storage Class
- Static Storage Class
- External Storage Class
-
Automatic Storage Class:
This is the default storage for all local variables. Variables are declared in a function without a special class stored just to allocate memory of the group and have local resources. Their lives are limited only when work calls for it.
Syntax
auto data_type variable_name = value;
-
Register Storage Class:
Variables are declared using class registers stored in CPU registers. This can improve performance because accessing the list is faster than accessing memory. However, the number of names is limited, so registration should be used with caution. The switches reportedly use a scratch pad to have the same capacity and lifespan as automatic switches.
Syntax
register data_type variable_name = value;
-
Static Storage Class:
Variables declared with statically stored classes allocate memory in the data section of the program and retain their values ​​between calls. They have a local area, but their life consists of the entire program. Functions can also be declared statically, and these functions can only be called from the source code in which they are defined.
Syntax
static data_type variable_name = value;
-
External Storage Class:
Variables declared using external storage classes are defined in a source code file and can be used in other code files. They are often used to specify global variables of various source code files. The extern keyword should be used to identify (not report) changes to the database and other files that use them.
Syntax
extern data_type variable_name;