http://www.dooccn.com/c/#id/49bbc74bd5e9657697a63e36ba8b0a9d
struct person
{
int age;
char name;
};
struct person p1 =
{
.age = 20,
.name = ‘c’,
};
int main()
{
printf(“age: %d\n”, p1.age);
printf(“name: %c\n”, p1.name);
}
下面打印字符串
struct person
{
int age;
char name[7];
};
struct person p1 =
{
.age = 20,
.name = “asdfgh”,
};
int main()
{
printf(“age: %d\n”, p1.age);
printf(“name: %s\n”, p1.name);
}
%%%%%%%%%%%%当结构体中的数组的大小声明为200时,编译不过,为什么???
struct person
{
int age;
char name[200];
};
printf(“name: %s\n”, p1.name);
报错: C99 designator ‘name’ outside aggregate initializer
我的理解:为了保证初始化成功,结构体元素的初始化老实用.或者->