函数的参数传递
来源:互联网 发布:java面试宝典pdf下载 编辑:程序博客网 时间:2024/05/16 07:30
函数的参数传递有两种方式,一是直接传值,二是引用。直接传值是将实参的值传递给函数工作区形参的副本中,在函数的执行过程中,改变的是副本的值,当函数执行完毕返回时,副本将被清除,原实参的值不会改变。当使用引用时,传递的是实参的地址,这时形参相当于实参的别名,函数执行时,直接改变原实参的值。
// aa.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <stdlib.h>#include <stdio.h>#include <string.h>void swap1(int a,int b);void swap2(int &a,int &b);void swap1(int a,int b) //传值{int temp;temp=a;a=b;b=temp;}void swap2(int &a,int &b) //引用{int temp;temp=a;a=b;b=temp;}int main(int argc, char* argv[]){ int m=3,n=5; swap1(m,n);printf("swap1:m=%d,n=%d",m,n); printf("\n"); swap2(m,n); printf("swap2:m=%d,n=%d",m,n);printf("\n"); return 0; }
阅读全文
0 0
- 函数的参数传递
- 函数的参数传递
- 函数参数的传递
- 函数的参数传递
- 函数参数的传递
- 函数的参数传递
- 函数的参数传递
- 函数参数的传递
- 函数参数的传递
- 函数参数的传递
- 函数参数的传递
- 函数参数的传递
- 函数参数的传递
- 函数的参数传递
- 函数的参数传递
- 函数的参数传递
- 函数的参数传递
- 函数参数的传递
- 51nod 1256 乘法逆元
- 1022. D进制的A+B (20)
- Codeforces 400B Inna and Huge Candy Matrix(模拟)
- 搜狗面试惨败经验
- VMware中CentOS设置静态IP -yellowcong
- 函数的参数传递
- 人生只若如初见——初见线程
- 哈希表
- 杭电2056、Rectangles
- CSS Sprite雪碧图
- 387. First Unique Character in a String
- 观察者模式--帮我把个风
- 【超分辨率】Enhanced Deep Residual Networks for Single Image Super-Resolution
- C