C++ pass by reference when using pointer

2 views
Skip to first unread message

Lei

unread,
Jul 29, 2013, 11:28:33 AM7/29/13
to programmin...@googlegroups.com
compare following results:
void swap (int *p1, int *p2) {
int tmp = *p1;
*p1=*p2;
*p2=tmp;
}

n1 = 10;
n2 = 20;
swap(n1, n2);
swap(&n1, &n2);

you will get the same results, why?
Reply all
Reply to author
Forward
0 new messages