Why Array?

Why is array so important and used in C.

Why ARRAY?
In a computer memory, you will find address like ‘101947’ , ‘159845’ or ‘856974’ or just like that. If we declare a variable of for example integer named ‘marks’ like this:
int marks=10;
An integer value takes 2 bytes of memory, that means in computer memory, it will store ‘marks’ variable in for example ‘101947 and 101948’ memory location. Simple. But if we have to store a data of students in a class, you will declare variable like this:
int marks1=10, marks2=15, marks3=8;
If you declare variable like this, you will face two problems.
1)No Uniformity.
If you declare variable like this, the uniformity can not be maintained. if we declare the marks of roll no. 1 with marksroll1, and marks of roll no. 2 with marksof2, do you find uniformity? Of course not.
2)Random Memory Allocation

If you declare variables like marks1,marks2,mark3, it will store the variables randomly in the memory locations. For example, marks1 at ‘101974-101975’, marks2 at ‘809547-809548’ and marks3 at ‘505684-505685’. But if we declare it as array, it will store it in a contiguous memory location, for example marks[1] at ‘101974-101975’, marks[2] at ‘101976-101977’, marks[3] at ‘101978-101979’.

Related Posts with Why Array?