Please note that when
you have multiple files and you define a global variable or function, which will be used in other
files also, then
extern
will be used in another file to give reference of the defined variable or
function. Also note that
extern
is used to declare a global variable or function in another file.
For example,
File 1: main.c
int count = 10;
main( )
{
write_extern( );
}
File 2: write.c
void write_extern(void)
extern int count;
void write_extern(void)
{
printf(“count is %i\n”, count);
}
Here, the
extern
keyword is being used to declare a count in another file. Now compile these two
files as follows:
gcc main.c write.c –o write
This creates a write file that can be used to produce a result by executing it. The count in
Do'stlaringiz bilan baham: |