0

When we use array?? With suitable example.

30th Nov 2016, 3:33 AM
Aniket Deshmukh
2 Respostas
+ 21
a chess board for example of a 2D array. each index represents every square in the board
1st Dec 2016, 1:29 AM
Jobelle
Jobelle - avatar
+ 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;
30th Nov 2016, 5:02 AM
Jacques Navarro
Jacques Navarro - avatar