32.0k views
1 vote
20 points

Suppose the following array is declared: int[ ] grades = {88, 92, 95, 83}; and the following integer is declared: int index = 1 + 6 % 3; What is the value of grades[index]?

1 Answer

4 votes

Answer:

92

Step-by-step explanation:

int index = 1 + 6 % 3;

Modulo is calculated before adding, so as first you need to calc 6 % 3, result is 0.

int index = 1 + 0 = 1;

Indexes in arrays starts from 0, ends in length - 1. So first element in the array has 0 as index, second element has 1 as idnex, etc. Your index = 1, so value of the second element in the grades will be your result. Finally, the answer is 92.

User Matt Eckert
by
5.1k points