P
pereges
Let's say I've a header file foo.h containing a global variable a.
/* foo.h */
#ifndef foo_h
#define foo_h
#include <stdio.h>
extern int a;
#endif
Now, suppose I want to access this variable in main.c, then I need to
include foo.h
/* main.c */
#include "foo.h"
#include <stdio.h>
int a;
int main()
{
a = 4;
return (0);
}
My question is why must I always declare the integer again in main.c
and that outside the function ( I got a warning for not doing so)
whereas the definition must be in the main routine.
/* foo.h */
#ifndef foo_h
#define foo_h
#include <stdio.h>
extern int a;
#endif
Now, suppose I want to access this variable in main.c, then I need to
include foo.h
/* main.c */
#include "foo.h"
#include <stdio.h>
int a;
int main()
{
a = 4;
return (0);
}
My question is why must I always declare the integer again in main.c
and that outside the function ( I got a warning for not doing so)
whereas the definition must be in the main routine.