结构数组:
struct student
{
int idNumber;
char name[15];
int age;
char department[20];
float gpa;
};
……
student S[3]={ {428004, "Tomato",20, "ComputerScience",84.5},
{428005, "OOTTMA",20, "ComputerScience",85.0},
{428006, "OTA",20, "ComputerScience",89.8}
};
跟一般数组用法一样。
=======================================================================================
结构指针:
student s1={428004, "Tomato",20, "ComputerScience",84.5}; //初始化结构变量
student *s1ptr=&s1; //定义结构指针变量,并把s1的地址赋值给s1ptr
void display(student *arg)
{
cout << "学号:" << arg->idNumber << "姓名:" << arg->name <<endl; //用箭头操作符访问成员数据
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。