結構體的形參或實參傳遞和和一般的程序一樣:
#include<stdio.h>
#include<string.h>
struct student //結構體定義
{
char name[10];
int age;
double height;
};
void chack(struct student *s) //和一般的程序一樣也要改成指針
{
strcpy(s->name,"LiLin");
s->age=80;
s->height=180;
}
int main()
{
struct student monitot={"WangLu",10,100};
printf("改變之前:name=%s age=%d height=%.2f\n",monitot.name,monitot.age,monitot.height);
chack(&monitot); //取結構體地址
printf("改變之后:name=%s age=%d height=%.2f\n",monitot.name,monitot.age,monitot.height);
return 0;
}
