#include <stdio.h> int main(){ int a = 100, b = 999, temp; int *pa = &a, *pb = &b; printf("a=%d, b=%d\n", a, b); /*****开始交换*****/ temp = pa; pa = pb; pb = temp; /*****结束交换*****/ printf("a=%d, b=%d\n", a, b); return 0; }
#include <stdio.h> int main(){ int a = 100, b = 999, temp; int *pa = &a, *pb = &b; printf("a=%d, b=%d\n", a, b); /*****开始交换*****/ temp = *pa; *pa = *pb; *pb = temp; /*****结束交换*****/ printf("a=%d, b=%d\n", a, b); return 0; }
能不能给我用画图解释一下上面两个交互时有*和没*的区别
temp = pa; 这里加是取pa存储区内存放的值,也就是&a
temp = pa; 你确定编译得过吗?int 指针赋值给int整型,给的是pa的地址