Print Values using Array in C++


This is a C++ program that initializes an integer array arr with five elements and then outputs each element on a separate line. The program first initializes the array arr with the values {1, 3, 5, 7, 9} using an array initializer. It then outputs each element of the array on a separate line using a series of cout statements.

Source Code

#include <iostream>
using namespace std;
int main()
{
  int arr[] = {1, 3, 5, 7, 9};
  cout<<arr[0]<<endl;
  cout<<arr[1]<<endl;
  cout<<arr[2]<<endl;
  cout<<arr[3]<<endl;
  cout<<arr[4]<<endl;
  return 0;
}
To download raw file Click Here

Output

1
3
5
7
9

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples