typedef to alias the structure
It can be anonymous or configuration of conventional construction, to facilitate later use.
#include<stdio.h>
typedef struct{ //匿名结构
float tank_capacity;
int tank_psi;
const char *suit_material;
} equipment; //结构的别名
typedef struct scuba{ //结构名
const char *name;
equipment kit;
} diver;
void badge(diver d){
//使用“点表示法”访问结构的值,不能使用下标
printf("Name:%s Tank:%2.2f(%i) Suite:%s\n",d.name,d.kit.tank_capacity,d.kit.tank_psi,d.kit.suit_material);
};
int main(){
diver randy = {"Randy",{5.5,3500,"Neoprene"}};
badge(randy);
return 0;
}
Assignment to structure elements
In the C language, when the structure is assigned, the computer copies the value of the structure. It is necessary to structure pointer
typedef sturct{
const char *name;
int age;
} turtle;
turtle t={"lisa",12}
(* t) .age and different meanings t.age
t.age equal * (t.age), which represents the contents of this memory cell.
Typically for easy reading (* t) .age another form of writing
(* t) .age T-==> age
T-> age means "point t by the age field structure."