Careers360 Logo
How Many Storage Classes are in C

How Many Storage Classes are in C

Edited By Team Careers360 | Updated on Mar 30, 2023 12:18 PM IST

Introduction

The C language was developed by Dennis Ritchie who worked at AT&T laboratories in the early 1970s. It is a middle-level language that is used for writing application services, compilers, and much more. It forms the basis of almost all the programming languages written in a systematic and structured order. It is well-defined, and the programme is broken into parts or functions so it is easier for the programmer to understand and write.

Purpose of Storage Class

In the C programming language, we write various programmes for which we often have to define and declare variables and their data types. The storage class is used to describe the features of a variable. The scope within which the variable will store its value, the lifetime of the variable, and the default value of variables are all dependent on the type of storage class. There are four types of storage classes, which are described below.

Background wave

Types of Storage Classes

  1. Auto

This is the default class of the variables. Whenever the class is not declared, it is set to auto; hence, the name "autored'', it is set to auto; hence, the name "auto." It can be called and used only within the block in which it is declared, and access is destroyed outside the block. By default, it returns a garbage value.

  1. Extern

It is also known as an external storage class because the scope of the variable is global, i.e., it can be used throughout the program. The keyword "extern" is used to declare the class. Its default value is set to 0.

  1. Static

As the word Static means constant the value of this variable will not change and remain static even when it is redeclared or tried to change in the block. However, it is visible only in the declared file. Its initial value is 0. The keyword used to declare this class is "static." This can further be classified as a local static variable or a global static variable. If the type is local then it can be called only inside the block. If the type is global, it can be accessed anywhere inside the program.

  1. Register

The keyword used to declare this is "register." Its scope is only within the block, and it sets the initial value as garbage. This is used where we expect quick results. The faster output is obtained because the CPU registers its value instead of storing it in RAM. Rest all of the classes and allocate RAM memory.

Storage Class
Memory
Default Value
Scope
Lifetime

Auto

RAM

Garbage

Within the Block Only

Only till the block is active

Extern

RAM

0

Anywhere In the Program

Till the end of program

Static

RAM

0

As per Declaration

Till the end of program

Register

Register

Garbage

Within the Block

Only till the block is active

Notes -

  • The C language is also known as the mother of all languages.

  • The UNIX system, Adobe Photoshop, Google, and MySQL are a few real-world applications of C.

  • The auto class is also called the automatic storage class.

  • C++ can be called an advanced level of the C language, but both are different.

  • The storage classes define the lifetime and scope of variables, whereas memory allocation is used to allocate space in the memory block.

Back to top