Monday, March 30, 2015

Extern Variable in 'C'

When we declare a variable without using extern then the variable is declared as well as memory is allocated to the variable. for e.g.
   int a;
This statement tell that there is a variable named 'a'. i.e. it is declared and memory of 4 bytes is allocated to 'a' i.e. it is defined. But if we use extern to declare a variable then it only declare the variable but does not allocate memory to it.for e.g.
   extern int a;
This statement only declare the variable 'a'. for allocating memory to variable 'a' we have to first initialize it. we can't use it directly in any statement.