天天看点

[C/C++] struct和typedef

C语言中,typedef 可用来的为类取别名,例如

typedef struct Student{
    int a;
} Stu;
//声明一个student类型的变量: 
Stu s;
或
struct Student s;
           

C++ 中struct的用法比较简单

typedef struct Student{
    int a;
}
//声明一个student类型的变量: 
Student s; 
           

typedef的用法略有不同:

“`

typedef struct Student{

int a;

} Stu; //此时Stu为一变量,可以直接在后续的代码中访问Stu.a,而在C语言中,需要提前声明变量,方可访问 Stu s;s.a;

““

继续阅读