Storage Class (in multiple files)
#include <stdio.h>
int p(void);
int cnt = 0;
main()
{
int k;
cnt = -10;
k = p();
printf("%d\n", k);
++cnt;
k = p();
printf("%d\n", k);
}
extern int cnt;
int p(void)
{
return ++cnt;
}
Define and initialize cnt as type int, storage class extern.
Declare cnt as extern. Thus cnt is the same variable defined in File 1.
File 1: main.c
File 2: p.c
Previous slide
Next slide
Back to first slide
View graphic version