//compile:g++ p_quote.c
//run: ./a.out
//c中没有引用,C++中有引用
#include<stdio.h>
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
void pq(int &a,int &b)
{
printf("quote a=%d b=%d\n",a,b);
printf("quote &a=%d &b%d\n",&a,&b);
swap(a,b);//交换
}
void p(int *a,int*b)
{
printf("point a=%d b=%d\n",a,b);
printf("point &a=%d &b=%d\n",&a,&b);
printf("point *a=%d *b=%d\n",*a,*b);
swap(*a,*b);//交换
}
int main()
{
int aa=0,bb=1;
printf("main val %d %d\n",aa,bb);
printf("main addr %d %d\n",&aa,&bb);
pq(aa,bb);
printf("after quote swap:a=%d b=%d\n",aa,bb);
p(&aa,&bb);
printf("after point swap:a=%d b=%d\n",aa,bb);
return 0;
}