Introduction
Are you eager to gain a better understanding of computer programming? Do you love the challenge of learning a new skill and building complex programs? If so, then an excellent place for you to begin is by exploring the fundamentals of Storage Class in C. In this article, we'll take a closer look at storage class in C and how it influences different aspects of programming from memory management to declaring variables. Understanding storage class can mean the difference between a basic program and one that is robust, reliable, and efficient making it essential knowledge for any aspiring programmer! Dive into this journey with us as explore what lies beneath the surface of storage classes in C.
What is Storage class in C
The fascinating world of programming in C is full of features that allow developers to create versatile, efficient, and powerful applications. Storage classes in C play a pivotal role in determining the scope, visibility, and lifetime of variables and functions within the program. As the users delve deeper into C programming, they will encounter four essential storage classes, each with its specific behavior and functionality. These include automatic, register, static, and external, which provide distinctive ways to handle variable storage and allocation. By mastering these storage classes, the users will possess the ability to optimize their code, ensure the smooth execution of their projects, and tackle real-world programming challenges with grace and expertise. So, embark on the coding journey and unleash the full potential of C programming by understanding and making use of storage classes in C.
Types of Storage class in C

- Automatic storage class in C
- Static storage class in c
- Register storage class in c
- External storage class in c
Storage Classes | Storage Place | Default Value | Scope | Lifetime |
auto | RAM | Garbage Value | Local | Within function |
extern | RAM | Zero | Global | Till the end of the main program Maybe declared anywhere in the program |
static | RAM | Zero | Local | Till the end of the main program, Retains value between multiple functions call |
register | Register | Garbage Value | Local | Within function |
Automatic storage class in c
Automatic storage class in c is one of the most basic and important aspects of the C programming language. This class enables the user to declare variables without having to specify their type at run time. It also provides a way for c-programmers to declare variables of a specific type, such as int, double, and char. Automatic Storage Class in C is so named because it allows the computer's compiler to automatically assign storage space from a given pool that is available. Automatic Storage Class allows users to write more efficient code by allowing them to access memory more quickly than if each variably needed manual allocation. Automatic Storage can help create organized code by allowing the user to assign certain types of data in a logically appropriate area within a program's overall code base. Automatic Storage Class can thus greatly improve the clarity, efficiency, and effectiveness of a program.
Example
#include <stdio.h>
int main()
{
int a; //auto
char b;
float c;
printf("%d %c %f",a,b,c); // printing initial default value of automatic variables a, b, and c.
return 0;
}
Output
garbage garbage garbage
Static storage class in c
Example
#include<stdio.h>
static char c;
static int i;
static float f;
static char s[100];
void main ()
{
printf("%d %d %f %s",c,i,f); // the initial default value of c, i, and f will be printed.
}
Output
0 0 0.000000 (null)
Register storage class in c
Example
#include <stdio.h>
int main()
{
register int a; // variable a is allocated memory in the CPU register. The initial default value of a is 0.
printf("%d",a);
}
Output
0
External storage class in c
Example
#include <stdio.h>
int a;
int main()
{
extern int a; // variable a is defined globally, the memory will not be allocated to a
printf("%d",a);
}
Output
0
Summary
Take our free skill tests to evaluate your skill!

In less than 5 minutes, with our skill test, you can identify your knowledge gaps and strengths.