C++ Program to Access Elements of an Array Using Pointer
In this example, we will learn to Access Elements of an Array Using Pointer.
To understand this example, you should have the knowledge of the following C++ programming topics:
Example: Program to Access Array Elements Using Pointer
#include <iostream>
using namespace std;
int main()
{
int data[5];
cout << "Enter elements: ";
for(int i = 0; i < 5; ++i)
cin >> data[i];
cout << "You entered: ";
for(int i = 0; i < 5; ++i)
cout << endl << *(data + i);
return 0;
}
Output
Enter elements: 1 2 3 5 4 You entered: 1 2 3 5 4
Working
In this program, the five elements are entered by the user and stored in the integer array data.
Then, the data array is accessed using a for loop and each element in the array is printed onto the screen.
Visit this page to learn about relationship between pointer and arrays.
Next Example
We hope that this Example helped you develop better understanding of the concept of "Access Array Elements Using Pointer" in C++.
Keep Learning : )
In the next Example, we will learn about C++ Swap Numbers in Cyclic Order (Call by Reference)
.