Monday, March 18, 2013
4:28 PM

Solution: Access Variables in Different C files

To access variables in different C files, check below example

header.h 
extern int a;

file1.c
#include</root/path/header.h>
int a;
a = 20;

file2.c
#include</root/path/header.h>
printf("a value is %d",a);

Note: if you compile individual file and check then you may get error 
Compile like:
gcc file1.c file2.c -o out
./out
Output: a value is 20

0 comments:

Post a Comment