EXTERNAL STORAGE CLASS

Extern storage class:

The location of the extern 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 global.

Extern will differ from all the remaining storage classes in terms of the scope. It is global in nature means, this variable will be used by all the functions irrespective of their decleration.

Example:

Extern int  i ;

Void main( )

{

 printf ( "i = %d", i ) ;

inc( ) ;

inc( ) ;  

dec( ) ;  

dec( ) ;

}

 inc( )

{

 i = i + 1 ; 

printf ( "i = %d", i ) ;

}

dec( )

 {

  i = i - 1 ; 

printf (“i = %d", i ) ;

 }

Output:

1210

Explanation:

The variable i is declared as extern means, a method which has the variable  i in it can access that irrespective of the scope. The function inc can make use of i as well as dec also, which increments and decrements the values of the variable i.

Contributor's Info

Created:
0Comment