1. 程式人生 > >C語言結構體引數傳遞

C語言結構體引數傳遞

結構體的形參或實參傳遞和和一般的程式一樣:

#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;
}