Array.
Array is basically a contiguous memory allocation of same data type.It can't be of different data type.
It is a homogeneous continuous memory allocation.
We will learn about:
- What is an Array
- Declaring and initializing
- Accessing array element
1.What is an array:
Array is basically a contiguous memory allocation of same data type.It can't be of different data type.
It is a homogeneous continuous memory allocation.
2.Declaring and initializing:
int A[5];
The above statement is used for declaring an array.
int A[5] = {1,2,3,4,5};
The above statement is used for initialing an array.
Program to illustrate difference between declaring and initializing:
#include<iostream>
using namespace std;
int main()
{
int A[5];
int B[5] = {1,2,3,4,5};
for(int i=0;i<5;i++)
{
cout<<"Enter element for array A";
cin>>A[i];
}
for(int i=0;i<5;i++)
{
cout<<A[i]<<" ";
}
cout<<endl;
for(int i=0;i<5;i++)
{
cout<<B[i]<<" ";
}
return 0;
}
3.Accessing array element:
We can access array element with their position index.
Program that will explain how to access array element:
#include<iostream>
using namespace std;
int main()
{
int A[5];
for(int i=0;i<5;i++)
{
cout<<"Enter element for array A";
cin>>A[i];
}
for(int i=0;i<5;i++)
{
cout<<A[i]<<" ";
}
return 0;
}
Programs on array:
- Insertion in array
- Deletion in array
- Finding an index of a element in array
- Finding whether an element in present in an array or not
- How to increase an array size
0 Comment to "Arrays for beginners for free."
Post a Comment
If you have any doubts then let me know.