C语言递减指针

#include stdio.hconst int MAX = 3;int main () {intvar[] = {10, 100, 200};inti, *ptr;/* let us have array address in pointer */

编程学习网为您整理以下代码实例,主要实现:C语言递减指针,希望可以帮到各位朋友。

#include <stdio.h>

const int MAX = 3;

int main () {

   int  var[] = {10, 100, 200};
   int  i, *ptr;

   /* let us have array address in pointer */
   ptr = &var[MAX-1];

   for ( i = MAX; i > 0; i--) {

      printf("Address of var[%d] = %x\n", i-1, ptr );
      printf("Value of var[%d] = %d\n", i-1, *ptr );

      /* move to the prevIoUs location */
      ptr--;
   }

   return 0;
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐