2.6. Typedef Names2.6. typedef 名字A typedef lets us define a synonym for a type: typedef 可以用来定义类型的同义词: typedef double wages; // wages is a synonym for double typedef int exam_score; // exam_score is a synonym for int typedef wages salary; // indirect synonym for double A typedef name can be used as a type specifier: typedef 名字可以用作类型说明符: wages hourly, weekly; // double hourly, weekly; exam_score test_result; // int test_result; A typedef definition begins with the keyword typedef, followed by the data type and identifier. The identifier, or typedef name, does not introduce a new type but rather a synonym for the existing data type. A typedef name can appear anywhere in a program that a type name can appear. typedef 定义以关键字 typedef 开始,后面是数据类型和标识符。标识符或类型名并没有引入新的类型,而只是现有数据类型的同义词。typedef 名字可出现在程序中类型名可出现的任何位置。 Typedefs are commonly used for one of three purposes: typedef 通常被用于以下三种目的:
![]() |