difference between pointer and reference
Posted on 2011-02-24 22:18 alexkk2011 阅读(166) 评论(0) 编辑 收藏 举报#include <iostream> using namespace std; void swapf(char* a, char* b) { int n1 = *a, n2 = *b; n1=n1+n2; n2=n1-n2; n1=n1-n2; *a=n1, *b=n2; }; void main() { char x ='a', y='B'; char *px = &x, *py = &y; char &rx = x, &ry =y; swapf(&x, &y); cout << x << " " << y << endl; swapf(&rx, &ry); cout << x << " " << y << endl; swapf(px, py); cout << x << " " << y << endl; }