Social Icons

10 July 2012

0 External Storage Class in C

The feature of a variable defined to have a external storage class are as follows :
A external variable is declared by using keyword extern.
Syntax :
static type var-name; or type static var-name;

Storage                                   :               Computer Memory

Scope                                      :               Global

Default Initial Value            :               Zero

Lifetime                                 :               Lifetime of the program
The variables of this class can be referred to as 'global or external variables.' They are declared outside the functions and can be accessed by all the functions that are willing to use them.

What are advantages and disadvantages of external storage class?

Advantages of external storage class
1)Persistent storage of a variable retains the latest value
2)The value is globally available
Disadvantages of  external storage class
1)The storage for an external variable exists even when the variable is not needed
2)The side effect may produce surprising output
3)Modification of the program is difficult
4)Generality of a program is affected

Example:

#include <stdio.h>
void Display(void); 
extern int i=10; //global
int main()
 {
  int i=20;    // local to main()
printf("\n %d",i);
  Display();
  return 0;
}
void Display(void)
{
  printf("\n %d",i);
}
  
Output:
20
10

0 comments:

Post a Comment

Hey this is a test comment

Related Posts Plugin for WordPress, Blogger...