博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在其他文件中调用结构体变量
阅读量:4167 次
发布时间:2019-05-26

本文共 337 字,大约阅读时间需要 1 分钟。

写个头文件 c.h  声明 一个结构体类型 struct STU {
int x; int y; }; 定义结构体变量s的文件b.c #include "c.h" struct STU s; /* 不加extern ,默认认为extern */ a.c 调用b.c里定义的全局变量s #include
#include "c.h" /* struct STU这个类型的定义(或者说声明)在这个头文件里 */ extern struct STU s;/* 声明它是外部的类型是struct STU */ int main() {
printf("s.x+s.y = %d+%d = %d\n",s.x,s.y,s.x+s.y);/*调用了*/ }

转载地址:http://wrhxi.baihongyu.com/

你可能感兴趣的文章
2018.4.34
查看>>
2018.4.35
查看>>
2018.4.36
查看>>
我为什么要写博客
查看>>
如何导入pycharm无法导入的包
查看>>
2018.4.37
查看>>
2018.4.38
查看>>
2018.4.39
查看>>
2018.4.40
查看>>
2018.5.27
查看>>
2018.5.51
查看>>
2018.5.52
查看>>
《python基础教程》答案(第四章)
查看>>
2018.5.53
查看>>
2018.5.54
查看>>
2018.5.55
查看>>
2018.5.58
查看>>
2018.12.5
查看>>
2018.12.6
查看>>
人智导(四):约束满足问题
查看>>