Right Click to Search

Sunday, January 24, 2025

External ( extern ) storage class in C Programming




External ( extern ) storage class in C Programming

  1. Variables of this storage class are "Global variables"
  2. Global Variables are declared outside the function and are accessible to all functions in the program
  3. Generally , External variables are declared again in the function using keyword extern
  4. In order to Explicit declaration of variable use 'extern' keyword
extern int num1 ;   // Explicit Declaration  
Features :
 Storage
Memory
 Scope
Global / File Scope
 Life time

  • Exists as long as variable is running
  • Retains value within the function
 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 :
  1. Declaration within the function indicates that the function uses external variable
  2. Functions belonging to same source code , does not require declaration (no need to write extern)
  3. If variable is defined outside the source code , then declaration using extern keyword is required

Bookmark & Share

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates