采用值传递为什么2值不交换呢?
2012-12-22 19:29
239 查看
#include<iostream>
using namespace std;
void swapr(int &a,int &b);
void swapp(int *q,int *p);
void swapv(int a,int b);
int main()
{
system ("color d");
int a,b;
cout<<" 原始的两值为:";
cin>>a>>b;
cout<<"a="<<a<<' '<<"b="<<b<<endl;
cout<<"采用引用传递后:";
swapr(a,b);
cout<<"a="<<a<<' '<<"b="<<b<<endl;
cout<<"采用指针传递后:";
swapp(&a,&b);
cout<<"a="<<a<<' '<<"b="<<b<<endl;
cout<<" 采用值传递后:";
swapv(a,b);
cout<<"a="<<a<<' '<<"b="<<b<<endl;
return 0;
}
void swapr(int &a,int &b)
{
int t;
t=a;
a=b;
b=t;
}
void swapp(int *q,int *p)
{
int t;
t=*q;
*q=*p;
*p=t;
}
void swapv(int a,int b)
{
int t;
t=a;
a=b;
b=t;
}
采用值传递,为什么a和b没有交换值,看了书也没弄明白,知道的大侠详细的说下(我自学C++,所以.....)!
听君一句话,胜读十年书!!
谢谢你们了!!
using namespace std;
void swapr(int &a,int &b);
void swapp(int *q,int *p);
void swapv(int a,int b);
int main()
{
system ("color d");
int a,b;
cout<<" 原始的两值为:";
cin>>a>>b;
cout<<"a="<<a<<' '<<"b="<<b<<endl;
cout<<"采用引用传递后:";
swapr(a,b);
cout<<"a="<<a<<' '<<"b="<<b<<endl;
cout<<"采用指针传递后:";
swapp(&a,&b);
cout<<"a="<<a<<' '<<"b="<<b<<endl;
cout<<" 采用值传递后:";
swapv(a,b);
cout<<"a="<<a<<' '<<"b="<<b<<endl;
return 0;
}
void swapr(int &a,int &b)
{
int t;
t=a;
a=b;
b=t;
}
void swapp(int *q,int *p)
{
int t;
t=*q;
*q=*p;
*p=t;
}
void swapv(int a,int b)
{
int t;
t=a;
a=b;
b=t;
}
采用值传递,为什么a和b没有交换值,看了书也没弄明白,知道的大侠详细的说下(我自学C++,所以.....)!
听君一句话,胜读十年书!!
谢谢你们了!!
相关文章推荐
- 某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用 和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。
- 【程序48】 题目:某个公司采用公用电话传递数据,数据是四位的整数, 在传递过程中是加密的,加密规则如下:每位数字都加上5, 然后用和除以10的余数代替该数字,再将第一位和第四位交换, 第二位
- 题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。
- java某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。
- 某公司采用公用电话传递数据,数据是四位数,数据是加密的,加密规则如下:每位数字都加上5,用它们的和除以10的余数替代该数字,第一位和第四位交换,第二位和第三位交换..,
- 计算机网络复习 主题2 :为什么因特网采用分组交换的方式进行数据交换
- 某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。
- 二进制的计算(计算机为什么采用补码存储数据)
- 为什么要采用UTF-8编码,UTF-8编码有什么好处?
- 计算机为什么采用补码的形式存储数据?
- 一个完整的通过encoding/json信息传递格式,采用http.POST利用进行与服务器通信,并对返回结果进行解析处理的典型案例
- 为什么能用位运算来交换数据
- 采用CURL库在PHP程序之间传递数组
- 【程序48】 TestCode.java 题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下 //:每位数字 都加上5,然后用和除以10的余数代替该数字,再将
- .net和js数据交换url传递编码解码
- 为什么异或运算可以实现两个整数的交换,而无需借助第3个临时变量
- 废除“竖井”转向“SOA” 为什么要采用SOA
- 为什么采用达龙平台实施桌面虚拟化更合适?
- 采用curl库在PHP程序之间传递数组[转载]
- 基本数据类型的包装类型作为参数传递,以及其他引用类型作为参数传递,以及List中值的交换的一些问题