//声明结构体
struct student{
//内部声明成员
int id;
char name[30];
int age;
char gender;
char address[50];
};
int main(){
//声明结构体变量
struct student s1={9527,"linlei",18,'g',"wuhanshengchai"};
//错误,针对于数组不能重新赋值
//s1.name="cyj";
printf("id=%d,name=%s,age=%d,gender=%c,address=%s\n",
s1.id,s1.name,s1.age,s1.gender,s1.address);
strcpy(s1.name,"cyj");
s1.gender='N';
s1.age=19;
strcpy(s1.address,"zhongshanhuangpu");
printf("id=%d,name=%s,age=%d,gender=%c,address=%s",
s1.id,s1.name,s1.age,s1.gender,s1.address);
}
初识结构体
最新推荐文章于 2024-05-31 10:46:10 发布