C语言 typedef
C 语言提供了 typedef 关键字,我们可以使用它来为类型取一个新的名字;
C typedef 示例
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Student
{
int age;
char name[20];
}Stu;
int main()
{
Stu stu1;
stu1.age = 10;
strcpy(stu1.name, "aaa");
printf("name = %s, age = %d\n", stu1.name, stu1.age);
return 0;
}
之前我们定义Student的时候,要申明变量时,总是要带上 struct, 现在我们加了typedef, 就不用在带上struct了;
运行结果为
name = aaa, age = 10