C语言中的加加减减(三)

2014-02-08 12:44:22 · 作者: · 浏览: 767

 

  执行结果:

  ++*p:先取出p指向的数字,再将这个数字加1

  [cpp] view plaincopy

  #include

  int main()

  {

  int a = {1,8,10,5,2};

  int *p;

  p = a;

  printf("%d\n",++*p);

  return 0;

  }

  执行结果:

  --*p:先取出p指向的数字,再将这个数字减1

  [cpp] view plaincopy

  #include

  int main()

  {

  int a = {1,8,10,5,2};

  int *p;

  p = a;

  printf("%d\n",--*p);

  return 0;

  }

  执行结果:

  *(p++) :p与++先结合(而不是*)先结合,这个先是运算符跟谁结合在一起而不是时间的先后

  如 t = *(p++);

  等价于 t = *p;p++;

  [cpp] view plaincopy

  #include

  int main()

  {

  int a = {1,8,10,5,2};

  int *p;

  p = a;

  printf("%d\n",*(p++));

  printf("%d\n",*p);

  return 0;

  }

  执行结果:

  *(p--) :p与--先结合(而不是*)先结合,这个先是运算符跟谁结合在一起而不是时间的先后

  如 t = *(p--);

  等价于 t = *p;p--;

  [cpp] view plaincopy

  #include

  int main()

  {

  int a = {1,8,10,5,2};

  int *p;

  p = a;

  printf("%d\n",*(p--));

  printf("%d\n",*p);

  return 0;

  }

  执行结果: