c++ 递增一个指针


#include <iostream>

using namespace std;
const int MAX = 3;

int main ()
{
   int  var[MAX] = {10, 100, 200};
   int  *ptr;

   // 指针中的数组地址
   // 数组名是数组的首地址
   ptr = var;
   for (int i = 0; i < MAX; i++)
   {
      cout << "Address of var[" << i << "] = ";
      cout << ptr << endl;

      cout << "Value of var[" << i << "] = ";
      cout << *ptr << endl;

      // 移动到下一个位置
      ptr++;
   }
   return 0;
}
Address of var[0] = 0x7ffe878af7bc
Value of var[0] = 10
Address of var[1] = 0x7ffe878af7c0
Value of var[1] = 100
Address of var[2] = 0x7ffe878af7c4
Value of var[2] = 200
posted @ 2019-03-13 13:57  luoganttcc  阅读(431)  评论(0编辑  收藏  举报