I am having a problem with the following codes, especially in header.c, where I cannot access the extern int x variable in header.h ... Why? Is extern variable in .h not global? How can I use this in other files?
=== header.h ===
#ifndef HDR_H
#define HDR_H
extern int x;
void function();
#endif
=== header.c ===
#include <stdio.h>
#include "header.h"
void function()
{
printf("%d", x);
}
=== sample.c ===
int main()
{
int x = 1;
function();
printf("\n%d", x);
return 0;
}
source
share