在结构声明的分号之前声明的结构变量是否为全局变量

Is a structure variable declared before the semicolon of a structure declaration a global variable?

本文关键字:声明 结构 是否 全局变量 变量      更新时间:2023-10-16

结构定义之后声明的变量是全局变量还是局部变量?

struct student {
    int id; 
    char name [ 20 ];
} stud; 

stud是全局变量还是局部变量?

它可以是全局的,也可以是局部的。这取决于定义结构变量的位置:

全球

struct Foo {
    ...
} foo;
int main() {
    return 0;
};

当地

int main() {
    struct Foo {
        ...
    } foo;
    return 0;
};

No.该变量的作用域与您在下一行定义它的作用域相同。