0
When we use array?? With suitable example.
2 Respostas
+ 21
a chess board for example of a 2D array. each index represents every square in the board
+ 1
When you have many values of the same data type.
Let's say you have school grades for 20 students.
int myArray[20] = {68, 75 , 72, 80, 95 ...}
Holding the values in the array is less cumbersome compared to having individual variables.
int grade1 = 68;
int grade2 = 75;
int grade3 = 72;
int grade4 = 80;
int grade5 = 95;
int ...
Arrays allow you to iterate through all the values.
int sum;
for (int i = 0; i < 20; i++) {
int sum += myArray[i];
}
int average = sum / 20;