vs2008中的 值调用

piaomiao163 2008-12-19 02:57:06

// d.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
using namespace std;

void Swap(int a,int b);
int _tmain(int argc, _TCHAR* argv[])
{
int x(5),y(10);
cout << "x="<<x<<" y="<<y<<endl;
swap(x,y);
cout << "x="<<x<<" y="<<y<<endl;
system("pause");
}

void Swap(int a,int b)
{
int t;
t = a;
a = b;
b = t;
}






这段是值调用的形式啊·~并不是引用调用 为什么最后还是出现了a b 值的交换啊.
...全文
71 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fox000002 2008-12-19
  • 打赏
  • 举报
回复
用的不是一个函数啊

注意下拼写
jieao111 2008-12-19
  • 打赏
  • 举报
回复
1楼正解,你调用的时候用Swap()试试
Learn-anything 2008-12-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 Vegertar 的回复:]
C/C++ code
#include "stdafx.h"
using namespace std;

void Swap(int a,int b);
int _tmain(int argc, _TCHAR* argv[])
{
int x(5),y(10);
cout << "x="<<x<<" y="<<y<<endl;
swap(x,y); ///////////////////////////////////你调用的是swap(),库中有这样的函数。
cout << "x="<<x<<" y="<<y<<endl;
system("pause");
}

void Swap(int a,int b)
{
int t;
t = a;

[/Quote]

up
dahua010 2008-12-19
  • 打赏
  • 举报
回复
你的声明是Swap 但是你调用的是swap
swap是库函数,你吧函数名字换成ccccccc你在试试
Vegertar 2008-12-19
  • 打赏
  • 举报
回复

#include "stdafx.h"
using namespace std;

void Swap(int a,int b);
int _tmain(int argc, _TCHAR* argv[])
{
int x(5),y(10);
cout << "x="<<x<<" y="<<y<<endl;
swap(x,y); ///////////////////////////////////你调用的是swap(),库中有这样的函数。
cout << "x="<<x<<" y="<<y<<endl;
system("pause");
}

void Swap(int a,int b)
{
int t;
t = a;
a = b;
b = t;
}


65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧