#include <stdio.h>
struct struct_out_main
{
int a;
};
void fun(void)
{
// struct struct_in_main var1; //这条语句会报错,因为struct struct_in_main的定义在这个函数内是不可见的,它只在main()中可见
struct struct_out_main var2;
// var1.a = 3;
var2.a = 4;
return;
}
int main(void)
{
struct struct_in_main
{
int a;
};
struct struct_in_main var1;
struct struct_out_main var2;
var1.a = 1;
var2.a = 2;
return 0;
}
本文探讨了C语言中结构体的定义与使用,并重点分析了结构体在不同作用域内的可见性问题。通过示例代码展示了在main函数内外定义结构体的区别及注意事项。
1058

被折叠的 条评论
为什么被折叠?



