main.c中
#include<stdio.h>
#include "test.h" int a = 1; int b = 2; int main() { fun();//最终a 和 b 的值都能正常输出 getchar(); return 1; }
test.c
#include"test.h" extern int a; extern int b; int fun() { printf("fun's a is:%d\n",a); printf("fun's b is:%d\n", b); return a; }
test.h
#ifndef _INC_STDIO #include<stdio.h> #endif int fun();