Explain representation of an array in memory,with an example
Answers
Answered by
1
hii
What is an Array?
An array is a collection of variables in same datatype.
we can’t group different data types in array.
Like, combination of integer and char, char and float etc.
Hence Array is called as homogeneous data type.
Let’s consider the situation where we need to get 10 student’s age and store it for some calculation.
Since age is an integer type, we can store it something like below,
Example
int ag1, age2, age3, age4, age5, age6, age7, age8, age9, age10;
if we declare like above, it will be very difficult for us to manipulate the data.
If more number of student joins, then it is very difficult to declare a lot of variables and keep track of it.
To overcome this kind of situation, we should use Array data structure.
What is an Array?
An array is a collection of variables in same datatype.
we can’t group different data types in array.
Like, combination of integer and char, char and float etc.
Hence Array is called as homogeneous data type.
Let’s consider the situation where we need to get 10 student’s age and store it for some calculation.
Since age is an integer type, we can store it something like below,
Example
int ag1, age2, age3, age4, age5, age6, age7, age8, age9, age10;
if we declare like above, it will be very difficult for us to manipulate the data.
If more number of student joins, then it is very difficult to declare a lot of variables and keep track of it.
To overcome this kind of situation, we should use Array data structure.
Similar questions
English,
7 months ago