External Storage Class : (Extern) in C Programming
External ( extern ) storage class in C Programming
- Variables of this storage class are “Global variables”
- Global Variables are declared outside the function and are accessible to all functions in the program
- Generally , External variables are declared again in the function using keyword extern
- In order to Explicit declaration of variable use ‘extern’ keyword
extern int num1 ; // Explicit Declaration
Features :
Storage | Memory |
Scope | Global / File Scope |
Life time |
|
Default initial Value | Zero |
Live Example :
int num = 75 ;
void display();
void main()
{
extern int mum ;
printf("nNum : %d",num);
display();
}
void display()
{
extern int mum ;
printf("nNum : %d",num);
}
Output :
Num : 75
Num : 75
Note :
- Declaration within the function indicates that the function uses external variable
- Functions belonging to same source code , does not require declaration (no need to write extern)
- If variable is defined outside the source code , then declaration using extern keyword is required
