Speed up development with full-stack environments for every branch.

Learn More

Display an Array Using For Loop [C++]

Forked from C++ Examples for Templates in C++.

5947 Runs 52416 Views 8434 Copies

In this example, we declare and initialize a constant size array and then display all the elements in the array using for loop



rizwan34 37

published 3 years ago

#include <iostream>

using namespace std;
/*  This example shows use of for loops.  							                  */

int main()
  const int array_size = 10; //array size
  int array[array_size] = {32,85,41,9,78,35,24,10,1,65}; //array with 10 elements
  cout << "Displaying Array..." << endl;
  //for loop that iterates through the while array and display all its elements
  for(int i = 0; i < array_size; i++)
    //array[i] represent ith element in the array.e.g 0th element is 32, 4th element is 78 etc
    cout << "Array[" << i << "] => " << array[i] << endl;
  return 0;
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).