1.除了数组外,其他都有副本机制(包括结构体数组)

2.结构体作为参数具有副本机制,结构体返回值也有副本机制 。

3.函数的参数和返回值都有他的副本机制。

#include<stdio.h>
int a=,b=;
static int sum(int aa,int bb){
printf("the aa is 0x%p,%d",&aa,aa);
printf("\nthe bb is 0x%p,%d",&bb,bb);
aa=;
return a+b;
}
int main(){
sum(a,b);
printf("\nthe a is 0x%p,%d",&a,a);
printf("\nthe b is 0x%p,%d",&b,b);
}

形参aa和bb是对a和b地址的拷贝。

#include<stdio.h>
int array[]={,};
static int arr(int arra[]){
printf("\nthe array is 0x%p,%d",arra,arra[]);
arra[]=;
return arra[]+arra[];
}
int main(){
arr(array);
printf("\nthe array is 0x%p,%d",array,array[]);
return ;
}

形参arra传入的是array的实际地址。

#include<stdio.h>
typedef struct{
int ar[];
int a;
}Struct; Struct my;
static void fuzhif(Struct mystruct){
mystruct.a=;
mystruct.ar[]=;
printf("\nthe mystruct address is:0x%p,ar address is:0x%p,%d,%d",&mystruct,mystruct.ar,mystruct.a,mystruct.ar[]);
} int main(){
my.a=;
my.ar[]=;
printf("\nthe my address is:0x%p,ar address is:0x%p,%d,%d",&my,my.ar,my.a,my.ar[]);
fuzhif(my);
printf("\nthe my address is:0x%p,ar address is:0x%p,%d,%d",&my,my.ar,my.a,my.ar[]);
return ;
}

形参mystruct传入的是结构体my的地址的拷贝。
#include<stdio.h>
typedef struct{
int ar[];
int a;
}Struct; Struct my; static void fuzhit(Struct *mystruct){
mystruct->a=;
mystruct->ar[]=;
printf("\nthe mystruct address is 0x%p,ar address is:0x%p,%d,%d",mystruct,mystruct->ar,mystruct->a,mystruct->ar[]);
} int main(){
my.a=;
my.ar[]=;
printf("\nthe my address is:0x%p,ar address is:0x%p,%d,%d",&my,my.ar,my.a,my.ar[]);
fuzhit(&my);
printf("\nthe my address is:0x%p,ar address is:0x%p,%d,%d",&my,my.ar,my.a,my.ar[]);
return ;
}

如果形参为结构体变量,那么可以通过结构体指针修改某一结构体变量的值。

最新文章

  1. linux awk的使用
  2. 外观模式(Facade Pattern)
  3. angularjs的一些优化小技巧
  4. OC语言-02面向对象的三大特性
  5. Object-C自定义对象NSLog输入信息
  6. js获取随机颜色
  7. 使用HAProxy、PHP、Redis和MySQL支撑每周10亿请求
  8. Android实用代码七段(三)
  9. Understanding about numerical stability, convergence and consistency
  10. 让大疆去做测绘---航线规划软件APP
  11. Win7 访问win2008 远程桌面提示:您的凭证不工作
  12. ThinkPHP5事务回滚
  13. ubuntu:如何制作类似jeso的系统?
  14. CSS3 动画的一些属性
  15. idea中pom.xml关于oracle配置
  16. mysql 大表优化
  17. Python学习札记(三十六) 面向对象编程 Object Oriented Program 7 __slots__
  18. Linux下which命令使用详解(转)
  19. Mac 访问隐藏文件方法! 网上方法在我电脑上都不可用!
  20. IO扩展控件(System.IO.Abstractions)

热门文章

  1. 对vue双向绑定的思考
  2. (八)Filter&amp;ThreadLocal实现处理事务
  3. CAD文件打印为PDF文档
  4. lua string方法拓展
  5. Protocol Buffers工作原理
  6. Java实现 LeetCode 887 鸡蛋掉落(动态规划,谷歌面试题,蓝桥杯真题)
  7. C# Winform退出程序的方法介绍
  8. 如何获取CSDN的积分?
  9. Java实现 LeetCode 558 四叉树交集(四叉树,第一次遇到,研究了半天)
  10. Java实现 蓝桥杯VIP 算法提高 陶陶摘苹果2