1. 程式人生 > >【C語言】用結構體陣列指標完成:有三個學生資訊,存放在結構體陣列中,要求輸出全部資訊

【C語言】用結構體陣列指標完成:有三個學生資訊,存放在結構體陣列中,要求輸出全部資訊

//用結構體陣列指標完成:有三個學生資訊,存放在結構體陣列中,要求輸出全部資訊
#include <stdio.h>
struct Stu
{
	int num;
	char name[20];
	char sex;
	int age;
};
int main()
{	struct Stu student[3]={{317,"han",'m',20},{318,"hun",'w',22},{311,"dan",'w',18}};
	struct Stu *p;
	printf("  num  name sex age\n");
	for(p=student;p<student+3;p++)
	{
		printf("%5d  %s  %c   %d\n",p->num,p->name,p->sex,p->age);
	}
	return 0;
}