小记C语言指针p与*p

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#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 @   Anleb  阅读(2172)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示