指针地址,返回值,参数在函数的传入传出总结

 1 //本段代码 使用2种子函数变量传入方式 和 3种子函数变量传出方式
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 int caculate(int *a,int b, int c);
 5 int main()
 6 {
 7     int *A;
 8     int s0=16,s1=2 ,result1=888,result2=999;
 9     A=(int*)malloc(sizeof(int));
10     printf("传入方法1:通过使用“&”传入int型变量地址,在子函数中修改内存实现变量传出

");
11     result2=caculate(&result1, s0,  s1);        //通过使用“&”传入int型变量地址,在子函数中修改内存实现变量传出
12     printf("传出方法1:通过地址符传入地址修改内存之后result1数结果为:%d
",result1);
13     printf("传出方法2:通过int函数返回值赋值int型变量result2数结果为:%d

",result2);
14     printf("传入方法2:预先定义指针A,指向申请的空间,A即此空间地址,传入子函数,实现子函数变量传出

");
15     caculate(A, s0,  s1);                        //预先定义指针A,指向申请的空间,A即此空间地址,传入子函数,实现子函数变量传出
16     printf("传出方法3:通过“*”指针指向内存单元编号为A的内容结果为: %d

",*A);
17     system("pause");
18     return 0;
19 }
20 int caculate(int *a,int b, int c)                //计算函数体,两种传入方式  1 “int型” 的用 “&变量” 传入 内容用“变量”提取
21 {
22                                                  //                            2 “*  型” 的用 “变量”  传入 内容用“*变量”提取
23     int tmp;
24     *a=b+c;
25     printf("子函数结果为:%d+%d=%d
",b,c,*a);
26     tmp=*a;
27     return tmp;
28 }
原文地址:https://www.cnblogs.com/Evence/p/4460603.html