#include <stdio.h>
#include<string.h>
#if 0
typedef struct stu
{
int id;
char name[20];
}STU;
int main()
{
STU stu1 = {1234,"hello"};
printf("id = %d,name = %s\n",stu1.id,stu1.name);
return 0;
}
#endif
#if 0
typedef struct student STU;
struct student
{
int id;
char name[100];
};
int main()
{
//STU stu1;
//stu1.id = 12343;
//strcpy(stu1.name , "hello");//数组不能直接复制,所以用strcpy
//printf("id = %d,name = %s\n",stu1.id,stu1.name);
STU stu2 = {.name = "hello", .id = 12345};
printf("id = %d,name = %s\n",stu2.id,stu2.name);
return 0;
}
#endif
结构体的定义与初始化
最新推荐文章于 2025-07-03 20:16:47 发布