Table of Contents

    Understanding Storage Classes in C: Types and Usage

    Understanding Storage Classes in C: Types and Usage

    From C compiler’s point of view, a variable name identifies some physical location within the computer where the string of bits representing the variable’s value is stored. There are basically two kinds of locations in a computer where such a value may be kept Memory and CPU registers. It is the variable’s storage class that determines in which of these two locations the value is stored.

    These are also called storage class specifiers

    These specifiers tell the compiler how to store the subsequent variable. The general form of a variable declaration that uses one is shown here:

    storage_specifier type var_name;
    Notice that the storage specifier precedes the rest of the variable declaration.

    A variable’s storage class tells us:

    1. Where the variable would be stored.
    2. What will be the initial value of the variable, if the initial value is not specifically assigned. (i.e. the default initial value).
    3. What is the scope of the variable; i.e. in which functions the value of the variable would be available.
    4. What is the life of the variable; i.e. how long would the variable exist.

    There are four storage classes in C:

    • Automatic storage class
    • Register storage class
    • Static storage class
    • External storage class


    Let us examine these storage classes one by one.

    Automatic Storage Class

    The features of a variable defined to have an automatic storage class are as under:

    Features Description
    Storage Memory
    Default initial value An unpredictable value, which is often called a garbage value
    Scope Local to the block in which the variable is defined
    Life Till the control remains within the block in which the variable is defined

    Register Storage Class

    The features of a variable defined to be of register storage class are as under:

    Features Description
    Storage CPU registers
    Default initial value Garbage value
    Scope Local to the block in which the variable is defined
    Life Till the control remains within the block in which the variable is defined

    Static Storage Class

    The features of a variable defined to have a static storage class are as under:

    Features Description
    Storage Memory
    Default initial value Zero
    Scope Local to the block in which the variable is defined
    Life Value of the variable persists between different function calls

    External Storage Class

    Features Description
    Storage Memory
    Default initial value Zero
    Scope Global scope
    Life scope As long as the program’s execution doesn’t come to an end.