Extern Variable

 Extern Variable:

The scope of this extern variable is throughout the main program. It is similar  to global variable. Definition for extern variable may be anywhere in the C program.

Example 1


int x1 = 10 ;

int main( )


extern int y1;

printf(“The value of x is %d \n”,x1);

printf(“The value of y is %d”,y1); return 0;


int y1=50;


The value of x is 10

The value of y is 50

Example 2


void display1();

int n1 = 5; // global variable

int main()


++n1; // variable n is not declared in the main() function


return 0;


void display1()


++n1; // variable n is not declared in the display() function

printf(“n = %d”, n1);



n = 7


Leave a Reply

Your email address will not be published. Required fields are marked *