QUESTION 1
Consider the following declarations:
const int NUMELS 10;
int values[NUMELS];
Which of the following array accesses is valid?
1. values[-1]
2. values[10]
3. values[0]
4. values[11]
QUESTION 2
Consider the following code segment that finds the maximum value store in an array named grade of size NUMELS.
What is the missing line of code indicated by the blank line?
___________
for (i = 1; i < NUMELS; i++)
if (grade[i] > maximum)
maximum = grade[i];
1. maximum = grade[1];
2. maximum = grade[0];
3. maximum = 100;
4. maximum = grade[NUMELS];
Question 1
The correct answer is option 3. values[0] will access the first value in that array
Question 2.
The correct answer is option 2. maximum = grade[0]; will initialize the maximum as the first element in the array.
Comments
Leave a comment