C中的extern关键字

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();

 

posted @ 2019-02-27 17:08  NULL_ROOT  阅读(253)  评论(0编辑  收藏  举报