1 Star 0 Fork 1

guohuacai/learnC2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
c语言中结构体的嵌套 653 Bytes
一键复制 编辑 原始数据 按行查看 历史
guohuacai 提交于 2020-12-23 20:35 . add c语言中结构体的嵌套.
#include <stdio.h>
struct info
{
int age;
char name[20];
} Info;
struct student
{
struct info info;
int score;
void (*display)(struct student *s);
};
void introduce(struct student *s)
{
printf("Hello,I am %s.\n", s->info.name);
printf("I am %d years old.\n", s->info.age);
printf("My score is %d.\n", s->score);
}
int main(int argc, char const *argv[])
{
struct student s =
{
18, "Mary", 89};
struct student *pStu = &s;
pStu->display = introduce;
pStu->display(pStu);
return 0;
}
结果:
Hello,I am Mary
I am 18 years old
My score is 89
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/guohuacai/learn-c2.git
git@gitee.com:guohuacai/learn-c2.git
guohuacai
learn-c2
learnC2
master

搜索帮助