STATIC STORAGE CLASS

Static storage class:

The location of the static storage class is memory. The default initial value is zero. The variable will be alive until the end. Their value persists along the function call. The variable scope is up to the block in which it is defined.

Example:

#include<stdio.h>

Void main()

{                     
fun_call();

func_call();

}

fun_call()

{
static int i =1;

Printf(ā€œ%dā€,i);

. i=i+1;

}

Output:

12

Explanation:

When function is called it executes and prints 1. And i is incremented to 2. After the 1st call, second call will happen, in that incremented i value I printed. But of we execute same by keeping i as auto, it will print 11.

 

The static variables are initialized only once, re initialization will not be allowed in the static storage class.

Contributor's Info

Created:
0Comment