C++指针和数组

#include iostreamusing namespace std;const int MAX = 3;int main () {intvar[MAX] = {10, 100, 200};

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

#include <iostream>

using namespace std;
const int MAX = 3;

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

   // let us have array address in pointer.
   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;

      // point to the next location
      ptr++;
   }

   return 0;
}

本文标题为:C++指针和数组

上一篇: C++递减指针
下一篇: C++指针数组

基础教程推荐