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

C++ program to print elements of an array using pointers.


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

Recommended Posts
C++ Program to Find Largest Element of an Array
C++ Program to Find Smallest Element in Array
C++ Program to Print Array in Reverse Order
C++ Program to Count Words in Sentence
C++ Program to Find Average of Numbers Using Arrays
C++ Program to Find Size of Variables using sizeof Operator
C++ Program to Find All Square Roots of a Quadratic Equation
C++ Program to Check Prime Number Using Function
C++ Program to Delete Spaces from String or Sentence
All C++ Programs