[Programming] C language struct pointer as function parameter, pointer Function
Struct pointer as function parameter:
The struct variable name represents the entire set itself, the entire set passed as a function parameter, that is, all members, rather than being converted into a pointer by the compiler like an array. If there are many struct members, especially when the Members are arrays, the transmission time and space overhead will be great, which affects the program running efficiency. Therefore, the best way is to use the struct pointer. In this case, only an address is transmitted from the real parameter to the form parameter, which is very fast.
# Include <stdio. h> struct stu {char * name; int score;} stus [] = {"zhangsan1", 65 },{ "zhangsan2", 98 }}; void averge (struct stu *, int); int main () {int len = sizeof (stus)/sizeof (struct stu); printf ("start... \ n "); // array name can be considered as a pointer averge (stus, len);} void averge (struct stu * stus, int len) {char * name; int score; int sum = 0; for (int I = 0; I <len; I ++) {name = stus [I]. name; // The first form score = (* (stus + I )). score; // second FORM sum + = score; printf ("% s... % d \ n ", name, score);} printf (" average score: % d... \ n ", sum/len );}