轻源码

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
一起源码网 门户 电脑主程序开源 查看主题

结构体数组的定义和引用(五)

发布者: 51111 | 发布时间: 2018-1-20 03:08| 查看数: 3076| 评论数: 1|帖子模式

2)指针法
若p指向数组的某一个元素,则p++就指向其后续元素。
3)指针的数组表示法
若p=student,我们说指针p指向数组student,p表示数组的第i个元素,其效果与
student等同。对数组成员的引用描述为:p.name、p.num等。
[例7-4]指向结构体数组的指针变量的使用。
structdata/*定义结构体类型*/
{
intday,month,year;
};
structstu/*定义结构体类型*/
{
char name[20];
long num;
struct data birthday;
};
main()
{inti;
structstu*p,student[4]={{"liying",1,1978,5,23},{"wangping",2,1979,3,14},
{"libo",3,1980,5,6},{"xuyan",4,1980,4,21}};
/*定义结构体数组并初始化*/
p=student;/*将数组的首地址赋值给指针p,p指向了一维数组student*/
printf("\n1----Outputname,number,year,month,day\n");
for(i=0;i<4;i++)/*采用指针法输出数组元素的各成员*/
printf("%20s%10ld%10d//%d//%d\n",(p+i)->name,(p+i)->num,
(p+i)->birthday.year,(p+i)->birthday.month,
(p+i)->birthday.day);
}

最新评论

tsy2500 发表于 2022-5-12 16:07
网页代码下载工具

浏览过的版块

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表