C/C++ 结构体 函数传递

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 struct student{
 5     int num;
 6     char str[20];
 7     double dec;
 8 };
 9 
10 void scan(struct student *stu){
11 //    scanf("%d%s%lf", &stu->num, stu->str, &stu->dec);
12     scanf("%d%s%lf", &(*stu).num, (*stu).str, &(*stu).dec);//.运算符优先级大于*
13 }
14 
15 void print(struct student stu){
16     printf("%d %s %lf\n", stu.num, stu.str, stu.dec);
17 }
18 
19 int main(){
20 
21     struct student stu;
22     
23     scan(&stu);
24     print(stu);
25 
26     return 0;
27 }
28 /*
29 20 字符串 20.02
30 */