Sunday 19 July 2020

Extern Variable



External variables are used to make global variables. Extern variable defined outside the function. These variables are available globally throughout the function execution. The value of global variables can be modified by the functions. “extern” keyword is used to declare and define the external variables.


Scope −  They are everywhere in the program i.e. global.
Default value − Default initialized value of global variable is Zero.
Lifetime − Till the end of the execution of the program.



#include <stdio.h>
extern int a = 32;
int b = 8;
void  main()
{
     auto int a = 28;
     extern int b;
     printf("The value of auto variable : %d\n", a);
     printf("The value of extern variables x and b : %d,%d\n", a, b);
     a = 15;
     printf("The value of modified extern variable x : %d\n", x);   
}

No comments:

Post a Comment