2011.12.3 指针引用01

#include <iostream>
#include <string.h>
using namespace std;
// void swap(int *p1,int *p2)
// {
//  int temp;
//  temp = *p1;
//  *p1 = *p2;
//  *p2 = temp;
// }
void swap(int &p1,int &p2)
{
 int temp;
 temp = p1;
 p1 = p2;
 p2 = temp;
}
int main()
{
 int a = 1,b = 2;
/* swap(&a,&b);*/
 swap(a,b);
 cout<<a<<endl<<b<<endl;
 return 0;
}

posted @ 2011-12-03 20:45  rookieeeeee  阅读(158)  评论(0编辑  收藏  举报