Array in C++ programming is a collection of the same type of data items, which is accessed by using common name. we use two types of arrays in C++ programming one-dimensional array and two-dimensional array.
#include<iostream.h>
#include<conio.h>
void main()
{ //'arr' is name of Array which length is 5 and assigning
int arr[5] = {2, 1, 3, 4, 63}; //values to it.
for(int i = 0; i < 5; i++) //loop looping from 0 to 5.
{
cout<<arr[i]<<endl; //and printing 'arr' Array Elements.
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{ //'arr' is name of Array which length is Not Defined and
int arr[] = {2, 1, 33, 4, 63}; //assigning values to it.
for(int i = 0; i < 5; i++) //loop looping from 0 to 5.
{
cout<<arr[i]<<endl; //and printing 'arr' Array Elements.
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[5]; //'arr' is name of Array and 5 is length of Array.
arr[0] = 1; //assigning Element to Every Index of 'arr' Array.
arr[1] = 5;
arr[2] = 65;
arr[3] = 0;
arr[4] = 13;
for(int i = 0; i < 5; i++)
{
cout<<arr[i]<<endl;
}
getch();
}