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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM