C语言_多个文件共用一个变量_关键字extern的应用

main.c

//第一个文件main.c
#include <stdio.h>
extern int a;	//全局变量声明 
int main(){
    printf("%d\n",a+1);
}

two.c

//另一个文件sub.c
int a=3;        //变量定义 

在这里插入图片描述

在这里插入图片描述

发布了172 篇原创文章 · 获赞 49 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_38769551/article/details/105432057