by Dinesh Thakur Category: Type And Variables

Extern variables: belong to the External storage class and are stored in the main memory. extern is used when we have to refer a function or variable that is implemented in other file in the same project. The scope of the extern variables is Global.

Example:

#include <stdio.h>
extern int x;
int main()
{
printf("value of x %d", x);
return 0;
}
int x = 3;

Here, the program written in file above has the main function and reference to variable x. The file below has the declaration of variable x. The compiler should know the datatype of x and this is done by extern definition.

Global variables: are variables which are declared above the main( ) function. These variables are accessible throughout the program. They can be accessed by all the functions in the program. Their default value is zero.

Example:

#include <stdio.h>
int x = 0;/*Variable x is a global variable. It can be accessed throughout the program */void increment(void) {
x = x + 1;
printf("\n value of x: %d", x);}
int main(){printf("\n value of x: %d", x);
increment();
return 0;
}
Related Articles of SQL


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content