电商网站怎么做的,动易网站cms,用html网站建设过程,跨境电商亚马逊开店流程整型数#xff0c;浮点数#xff0c;字符串是分散的数据表示#xff0c;有时候我们需要很多类型表示一个整体#xff0c;比如学生信息。 数组是元素类型一样的数据集合#xff0c;如果是元素类型不同的数据集合#xff0c;就要用到结构体 结构体一般是个模板#xff0c;…整型数浮点数字符串是分散的数据表示有时候我们需要很多类型表示一个整体比如学生信息。 数组是元素类型一样的数据集合如果是元素类型不同的数据集合就要用到结构体 结构体一般是个模板一般不给赋值每一项在实际中并不是都要使用。 如何定义一个结构体 1.告知系统是一个结构体用struct 2.添加结构体的名字 structStudent编程习惯要求结构体名字大写字母开头 3.最后大括号后边要添加分号 {}; eg struct Student { int num; char name[32]; char sex; int age; double score; char addr[32]; }; struct Day { int year; int month; int day; }; #include stdio.h
#include string.h
struct Student
{int num;char name[32];char sex[32];int age;double score;char addr[32];
};int main()
{int a;struct Student stu1;struct Student stu2 {2,小王,男,22,99,上海};a 10;stu1.num 1;//点运算符来访问结构体中的成员变量域stu1.age 10;stu1.score 69.5;strcpy(stu1.name,老王);strcpy(stu1.addr,深圳);printf(学号%d, 年龄%d, 分数%.2f, 姓名%s, 地址%s\n,stu1.num,stu1.age,stu1.score,stu1.name,stu1.addr);printf(学号%d, 年龄%d, 分数%.2f, 姓名%s, 地址%s\n,stu2.num,stu2.age,stu2.score,stu2.name,stu2.addr);return 0;
}