typedef
typedef是定义一种类型的别名,区别于define。
typedef 是由编译器执行解释的,#define 语句是由预编译器进行处理的。
举例:
eg1. typedef int BIEMING;
除此之外,typedef 还可以给数组、指针、结构体等类型定义别名。
eg2. typedef struct Student Stu;
相当于给struct Student 类型起了个别名,这里的Stu为数据类型。
用法:struct Student st1,st2(c++中可以直接Student st1, st2;);
等价于Stu st1,st2要访问结构体中的数据时st1.成员变量;
eg2实例
#include <stdio.h>
#include <string.h>
typedef struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
} Book;
int main( )
{
Book book;
strcpy( book.title, "C 教程");
strcpy( book.author, "Runoob");<