初始化一个变量体并引用,初始化、引用
#include<stdio.h>#include <string.h>//strcpy api使用需要添加此头文件
struct Student
{
int num;
char name[32];
char sex;
int age;
double scores;
char addr[32];
};
int main()
{
struct Student stu1;
struct Student stu2={2,"张三",'g',17,98.5,"北京"};//直接赋值
stu1.num=1;//内部结构赋值,点运算符来访问结构体中的成员变量(域)
stu1.age=10;
stu1.scores=98.5;
strcpy(stu1.addr,"福州");
strcpy(stu1.name,"chenlichen");
printf("学号:%d,年龄:%d,成绩:%2f,地址:%s,姓名:%s\n",
stu1.num,stu1.age,stu1.scores,stu1.addr,stu1.name);
printf("学号:%d,年龄:%d,成绩:%2f,地址:%s,姓名:%s\n",
stu2.num,stu2.age,stu2.scores,stu2.addr,stu2.name);
return 0;
}