指针修改变量地址
1 #include "stdafx.h" 2 #include<stdio.h> 3 #include<iostream> 4 using namespace std; 5 6 int main() 7 { 8 int a,b,*p1,*p2,*p3; 9 a=100; 10 b=200; 11 12 p1=&a; 13 p2=&b; 14 15 //int c=a+b; 16 printf("p1地址:%p\n",p1); 17 printf("p2的地址:%p\n",p2); 18 printf("a地址:%p\n",&a); 19 printf("b地址:%p\n",&b); 20 printf("a=%d\n",a); 21 printf("b=%d\n",b); 22 //printf("*p1=%d\n",*p1); 23 //printf("*p2=%d\n",*p2); 24 if(a<b) 25 { 26 p3=p1; 27 p1=p2; 28 p2=p3; 29 }; 30 //p1,p2的地址改变, a,b,的数值不变 31 printf("*p1=%d\n",*p1); 32 printf("*p2=%d\n",*p2); 33 printf("p1地址:%p\n",p1); 34 printf("p2的地址:%p\n",p2); 35 printf("a=%d\n",a); 36 printf("b=%d\n",b); 37 system("pause"); 38 return 0; 39 }