Before you kick start to reading array, you should understand why array concept is comes? How it is requires in C?
Array of characters is called a string whereas an array of ints or floats is called simply an array.
Let's read following program:
#include<stdio.h>
int main()
{
int r;
r=1;
r=2;
printf("The value of r = %d",r);
getch();
return 0;
}
The output of above program would be:
The value of r = 2
So, you can understand that when the value 2 is assigned into r, the earlier value of r (i.e. 1) is lost. Thus the ordinary variables are capable of holding only one value at a time.
What we do if we would want to store more than one value at a time in a single variable?
Here, the comes the concept of array.
What is array?
- Array is a collection of similar elements.
- The first element in the array is numbered 0, so the last element is 1 less than the size of the array.
- An array is also known as a subscripted variable.
- Before using an array, its type and dimension must be declared.
- The array elements are always stored in contiguous memory locations. This is a very important features of array.
Thus, an array is collection of similar elements. These similar elements could be all ints, or all floats, or all chars.

No comments:
Post a Comment