Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1682315
  • 博文数量: 210
  • 博客积分: 10013
  • 博客等级: 上将
  • 技术积分: 2322
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-25 15:56
文章分类

全部博文(210)

文章存档

2011年(34)

2010年(121)

2009年(37)

2008年(18)

我的朋友

分类: C/C++

2010-07-19 15:20:43

#include "stdafx.h"
#include<iostream>
#include<string>
#include<math.h>
#define swap(a,b) a = a+b;b=a-b;a=a-b;
using namespace std;
int swap2(int a,int b){
    int temp;
    temp = a;
    b = a;
    a = temp;
    return 0;
}
int main(int argc, _TCHAR* argv[])
{
    int x = 5,y = 10;
    swap(x,y);//一定要记住宏定义是做简单的替换,在此把a=a+b……展开,是操作的x,y。
    cout<<x<<y<<endl;
    swap2(x,y);//这个函数是操作的在swap2中的局部变量,对x,y的值不做改变
    cout<<x<<y<<endl;
}


阅读(895) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~