结构数组 (也就是结构体的数组)的组成:
struct 结构名 变量名[数组大小]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student {
char name[16];
int age;
};
int main(void){
struct student s[2];
printf("请输入第一个学生的姓名:\n");
scanf_s("%s",s[0].name, sizeof(s[0].name));
printf("请输入第一个学生的年龄:\n");
scanf_s("%d", &s[0].age, sizeof(s[0].age));
printf("第一个学生的姓名: %s, 年龄: %d\n", s[0].name, s[0].age);
s[1] = s[0];
memcpy(&s[1],&s[0], sizeof(struct student));
printf("第二个学生的姓名: %s, 年龄: %d\n", s[1].name, s[1].age);
system("pause");
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)