void swap1(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
void swap2(int **a, int **b) {
int t = **a;
**a = **b;
**b = t;
}
// 高级一点使用void**只是为了通用,可以交换各种类型
void swap3(void **a, void **b)
{
void *t;
t =*a;
*a =*b;
*b=t;
}
int main(int argc, char **argv) {
int a, b;
a = 16;
b = 32;
swap1(&a, &b);
printf("a=%d,b=%d \n", a, b);
int i = 3;
int j = 5;
int *p = &i;
int *q = &j;
printf("before *p=%d,*q=%d \n", *p, *q);
swap2(&p, &q);
printf("after *p=%d,*q=%d \n", *p, *q);
char *s1="abc";
char *s2="def";
swap3((void**)&p, (void**)&q);
swap3((void**)&s1, (void**)&s2);
printf("after s1=%c,s2=%c \n", *s1, *s2);
}