用自定义函数中的指针输入输出,Output函数传递地址
#include<stdio.h>
#include<string.h>
struct AGE
{
int year ;
int month ;
int day ;
};
struct Student
{
char name[20] ;
int num ;
struct AGE birthday ;
float score ;
};
void InputStudent( struct Student *p )
{
strcpy( p->name ,"小明" );
p->birthday.year = 1999 ;
p->birthday.month = 12 ;
p->birthday.day = 9 ;
p->num = 1234 ;
p->score = 100 ;
}
void OutputStudent( struct Student const *p )//const很重要,如果不加const的话,传递的参数就可能会通过地址发生改变
{
printf ("%s\n",p->name);
printf ("%d\n",p->num);
printf ("%d-%d-%d\n",p->birthday.year , p->birthday.month , p->birthday.day );
printf ("%f\n",p->score);
}
int main ()
{
struct Student stu1 ;
InputStudent(&stu1);
OutputStudent(&stu1) ;
return 0;
}