指向结构类型数组元素的指针

可用指针来指向结构类型数组元素,设pStudent为指向结构类型数组元素的指针变量,则pStudent也指向该结构类型数组元素,则pStudent也指向该结构类型数组的1个元素,pStudent+1指向2号元素,pStudent+i则指向i+1号元素,这与普通数组的情况是一样的

实例

#include <stdio.h>
#include <stdlib.h>
#define N 3
int main(void)
{
	struct StudentType
	{
		int num;
		char *name;
		char sex[3];
		int age;
		float score;
	};
	struct StudentType student[N]=
	{
		{10101,"µÂ»ªÁõ","ÄÐ",42,98.1},
		{10102,"ö¦Ó°ÕÅ","Å®",22,99.8},
		{10103,"ѧÓÑÕÅ","ÄÐ",43,96.5} 
	};
	struct StudentType *pStudent;
	for(pStudent=student;pStudent<student+N;pStudent++){
		printf("%8d",pStudent->num);
		printf("%12s",pStudent->name);
		printf("%6s",pStudent->sex);
		printf("%6d",pStudent->age);
		printf("%8.1f\n",pStudent->score);
	}
	system("PAUSE");
	return 0;
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值