Mega Code Archive

 
Categories / C++ Tutorial / Pointer
 

Using a pointer to print the contents of the array

#include <iostream> const int ARRAY_LENGTH = 5; using namespace std; int main () {    int Numbers [ARRAY_LENGTH] = {0, 100, 200, 300, 400};    const int *pInt = Numbers;    for (int nIndex = 0; nIndex < ARRAY_LENGTH; ++ nIndex)        cout << "Element [" << nIndex << "] = " << *(pInt + nIndex) << endl;    return 0; }