直接看代码
#include<stdio.h>
#include<stdlib.h>
struct animalType{
int tall;
int width;
int height;
};
struct animal{
struct animalType at;
int age;
};
void main(){
struct animal an={
.at={
.tall = 20,
.width = 100,
.height = 50,
},
.age = 200,
};
struct animalType at2 = an.at;
int tall = at2.tall;
int width = at2.width;
int height = at2.height;
int age = an.age;
printf("%d \n" , at2.height);
}
main函数中结构体的初始化前面的 . 不能少