C++ Program to Access Elements of an Array Using Pointer

In the previous article, we have discussed C++ Program to Multiply Two Matrices. In this article, we will see C++ Program to Access Elements of an Array Using Pointer.

C++ Program to Access Elements of an Array Using Pointer

  • How to traverse elements of an array using pointers in C++.
  • C++ program to print elements of an array using pointers.

C++ Program to print elements of an array using pointer

C++ Program to print elements of an array using pointer

#include <iostream>
 
using namespace std;
 
int main(){
   int array[100], num, i;
   cout << "Enter Number of elements\n";
   cin >> num;
   cout << "Enter " << num << " Integers\n";
   for(i = 0; i < num; ++i){
      cin >> array[i];
   }
   cout << "Array Content\n";
   for(i = 0; i < num; ++i){
      cout << *(array+i) << " ";
   }
   return 0;
}

Output

Enter Number of elements
6
Enter 6 Integers
7 3 2 5 9 1
Array Content
Enter 6 Integers
7 3 2 5 9 1

Know the collection of various Basic C++ Programs for Beginners here. So that you can attend interviews with more confidence.