1) 定义结构体数组的同时进行初始化
struct Car{
int lunzi;
int speed;
char name[20];
}cars[2]={{2,50},{80,300}};
2) 匿名
struct {
int lunzi;
int speed;
int speed;
}cars[2]={{2,50},{80,300}};
3)
struct Car cars[2]={{2,50},{80,300}};
4)先定义数组,后初始化
cars[0].lunzi = 4;
cars[0].speed = 200;
//cars[0].name="xxxx"; 错误的
strcpy(cars[0].name,"xxxx"); const char a;
通过数组角标整体去初始化 cars[1]=(struct Car){6,100}; |
|