How to iterate elements of array in C++

In this article, we will learn How to iterate elements of array in C++. We will iterate on a C++ array and print each element in that array.

How to read and print elements of an array in C++


#include <iostream>
#define MAX_SIZE 250

using namespace std;
 
int main()
{
    int Array[MAX_SIZE]; 
    int Size;
 
   
    cout<<"Please enter size of the array (Max 250): ";
    cin>>Size;
 
    
    cout<<"Please enter elements in array: ";
    for(int i=0; i<Size; i++)
    {
        cin>>Array[i];
    }
 
    cout<<"All  elements in array are:";
    for(int i=0; i<Size; i++)
    {

        cout<<"\t"<<Array[i];
        
    }
 
    return 0;
}

Output

Please enter size of the array (Max 250): 9
Please enter elements in array: 1
2
3
5
6
7
8
9
10
All  elements in array are:	1	2	3	5	6	7	8	9	10