【学习笔记】【C语言】结构体和函数

 1 #include <stdio.h>
 2 struct Student
 3 {
 4     int age;
 5     int no;
 6 };
 7 
 8 // 如果结构体作为函数参数,只是将实参结构体所有成员的值对应地赋值给了形参结构体的所有成员
 9 // 修改函数内部结构体的成员不会影响外面的实参结构体
10 void test(struct Student s)
11 {
12     s.age = 30;
13     s.no = 2;
14 }
15 
16 // 会影响外面的实参结构体
17 void test2(struct Student *p)
18 {
19     p->age = 15;
20     p->no = 2;
21 
22 }
23 
24 void test3(struct Student *p)
25 {
26     struct Student stu2 = {15, 2};
27     p = &stu2;
28     p->age = 16;
29     p->no = 3;
30 }
31 
32 int main()
33 {
34     struct Student stu = {28, 1};
35     
36     //test(stu);
37     //test2(&stu);
38     test3(&stu);
39     
40     printf("age=%d, no=%d\n", stu.age, stu.no);
41     
42     return 0;
43 }

 

 

转载于:https://www.cnblogs.com/dssf/p/4606325.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值