Q5 Write a C program to show the storage, default initial value, scope and life of a external storage class variable.

Write a C program to show the storage, default initial value, scope and life of a external storage class variable.

Program: 143

Write a C program to show the storage, default initial value, scope and life of external storage class variables.

Variable Storage Class tells us:

  1. Storage (location)
  2. Default Initial Value of the variable
  3. Scope of the variable
  4. Life of the variable

1. Storage: Where the variable would be stored.

2. Default Initial Value: What will be the initial value of the variable, if initial value is not specifically assigned. (i.e. the default initial value)

3. Scope: What is the scope of the variable: i.e. in which functions the value of the variable would be available.

4. Life: What is the life of the variable: i.e. how long would the variable exist.

External Storage Class:

Same as Static Storage Class but the life of the variable exists till the program’s execution does not come to end.

Storage : Memory
Default Initial Values : Zero
Scope : Global
Life : As long as the program’s execution doesn’t come to end.

#include<stdio.h>
int i; //external storage class variable
void increment();
void decrement();
int main()
{
    printf("\ni=%d\n",i);
    increment();
    increment();
    decrement();
    decrement();
    return 0;
}

void increment()
{
    i=i+1;
    printf("On incrementing i = %d\n",i);
}

void decrement()
{
    i=i-1;
    printf("On decrementing i = %d\n",i);
}

Output:

i=0
On incrementing i = 1
On incrementing i = 2
On decrementing i = 1
On decrementing i = 0

Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.