1) using struct variables as arguments to functions
When a struct variable is used as an argument of a function, the value is passed, and the contents of the memory unit of the structure variable are passed to the formal parameter in full order, and the parameter must be of the same type structure body variable
Demo
1# include <stdio.h>2# include <stdlib.h>3 4 //Create a student structure5 structStudent6 {7 Charname[ -];8 floatfscore[3];9}student={"Dire",98.5,89.0,93.5};//initializing struct-body variablesTen One voidDisplay (structStudent su)//formal parameters are the same type of structure (student structure) A { -printf"-----information------\ n"); -printf"name:%s", su.name); theprintf"chinese:%.2f\n", su.fscore[0]); -printf"math:%.2f\n", su.fscore[1]); -printf"english:%.2f", su.fscore[2]); -printf"average score is:%.2f\n", (su.fscore[0]+su.fscore[1],su.fscore[2])/3); + } - + intMain () A { at - Display (student); - - return 0; -}
Printf:
2) Use pointers to struct variables as function arguments
Demo:
1# include <stdio.h>2# include <stdlib.h>3 4 structStudent {5 Charname[ -];6 floatfscore[3];7}student = {"Dire",98.5,89.0,93.5};//initializing struct-body variables8 9 Ten voidDisplay (structStudent *pstruct) One { Aprintf"------information-------\ n"); -printf"name:%s\n",pstruct->name); -printf"chinese:%.2f\n", (*pstruct). fscore[0]); theprintf"math:%.2f\n", (*pstruct). fscore[1]); -printf"english:%.2f\n", pstruct->fscore[2]); - } - + - intMain () + { ADisplay (&student);//passing the first address of a struct variable into the pstruct pointer variable as an argument at - return 0; -}
3) Use members of struct variables as function parameters
This is the same way that a function passes a parameter as an argument to a normal variable, which is the value passed
C-language structure as a function parameter