初识C语言结构体
结构体使C语言有能力描述复杂类型
代码示例:
#include <stdio.h>
struct Panda
{
//成员
char name[30];
int age;
char sex[10];
char birth[20];
};
print(struct Panda* pHua)
{
printf("%s %d %s %s\n", (*pHua).name, (*pHua).age, (*pHua).sex, (*pHua).birth);
printf("%s %d %s %s\n", pHua->name, pHua->age, pHua->sex, pHua->birth);
//结构体指针变量->成员名
}
int main()
{
struct Panda Hua = { "HeHua",3,"mu","2020.07.04" };
printf("%s %d %s %s\n", Hua.name, Hua.age, Hua.sex, Hua.birth);
//结构体对象.成员名
print(&Hua);
return 0;
}
运行结果:
HeHua 3 mu 2020.07.04
HeHua 3 mu 2020.07.04
HeHua 3 mu 2020.07.04