ARRAY
- An array is a collection of finite number of elements of similar data type in contiguous memory.
- All the elements are stored under same name.
- It can be of any data-type.
The above image is an array. Each of them can be differentiate by their indexes.
Here is a Simple Code to Declare and Initialise an array of integer type in C++.
#include<iostream.h>
using namespcae std;
int main()
{
int arr[5]; //Declaration of an Array arr of int type.
int i;
cout<<"\n Enter the elements of the array : ";
//Initialising Array
for(i=0;i<5;i++)
{
cin>>arr[i];
}
//Displaying Array
for(i=0;i<5;i++)
{
cout<<arr[i];
}
return 0;
}
- Array always start from index 0.
- To access data at any point in array just type array_name[index]
Here is a Simple Code to Declare and Initialise an array of integer type in C++.
#include<iostream.h>
using namespcae std;
int main()
{
int arr[5]; //Declaration of an Array arr of int type.
int i;
cout<<"\n Enter the elements of the array : ";
//Initialising Array
for(i=0;i<5;i++)
{
cin>>arr[i];
}
//Displaying Array
for(i=0;i<5;i++)
{
cout<<arr[i];
}
return 0;
}
No comments:
Post a Comment