3045 - 【设计型】第12章:结构体与共同体 例7 向函数传递结构体(2)

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

定义一个学生结构体,数据成员包括学号,姓名,性别,生日(年月日),然后编写一个输出函数输出1个同学的数据。

注:要求用结构体指针做函数参数。

题目输入

题目输出

一行输出一个同学的数据。

输入/输出样例

输入格式

no input needed

输出格式

1001011 王丽 F 1995/10/12

C语言解答

#include<stdio.h> 
struct student 
{
long num;
char name[20];
char sex;
int year;
int month;
int day;	
}; 
void display (struct student *pt)
{
			   	printf("%ld %s %c %d/%d/%d\n",pt->num,pt->name,pt->sex,
				   pt->year,pt->month,pt->day);	
}
int main()
{
struct student stu={1001011,"王丽",'F',1995,10,12        
               };
               struct student *p=&stu;
              display(p); 
			   return 0;	
}