C 语言
typedef struct
typedef struct man
{
int age;
} stu;
这段代码定义了一个结构体变量struct man,别名 stu,声明变量有两种方法:
struct man leo;
stu leo;
此处 man 为 标识符,而 stu 是变量类型
typedef struct
{
int age;
} stu;
stu leo;
同上一段代码作用一样,但是声明变量只可以用
stu leo
C++
struct
struct man
{
int age;
};
man leo;
声明变量有两种方式,一种是在以上定义过后添加
man leo;
另一种是在定义时声明
struct man
{
int age;
} leo; //leo在这里是一个变量
typedef struct
typedef struct man
{
int age;
} stu; //stu在这里是一个结构体类型 = struct man
stu leo;
与不用 typedef 时造成了巨大的差别,此处应注意