小记C语言指针p与*p

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  int i1,i2,*p1,*p2,*p3;
  i1 = 4;
  i2 = 5;
  p1 = &i1;
  p2 = &i1;
  p3 = &i2;
  p1 = p3;
  printf("%d\n%d\n%d\n",*p1,*p2,*p3);
  system("PAUSE");	
  return 0;
}

 这是一次 指针值的交换,并非是指针指向的值的交换,看似有 1个地方存 指针这个变量的值,有另一个地方存指针指向的值。

指针的值 与 指针指向的值 是有差异的。

 

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  int i1,i2,*p1,*p2,*p3;
  i1 = 4;
  i2 = 5;
  p1 = &i1;
  p2 = &i1;
  p3 = &i2;
  *p1 = i2;
  printf("%d\n%d\n%d\n",*p1,*p2,*p3);
  system("PAUSE");	
  return 0;
}

 

这是 一次直接操作值,相当于 P1 p2 p3的指针值不变,指针指向的值变了

 

posted @ 2013-03-16 11:57  Anleb  阅读(2160)  评论(0编辑  收藏  举报