QUESTION 3
Considering the following declarations:
const int NUMELS 10;
int values[NUMELS];
Which of the following C++ statements correctly outputs the seventh element of the array?
1. cout << values << 7;
2. cout << values[6];
3. cout << values[7];
4. cout << values[8];
QUESTION 4
Consider the following declarations:
const int ARRAYSIZE = 7;
float length[ARRAYSIZE] = {7.8, 6.4, 4.9, 11.2};
What is the value of length[1] and length[4]?
1. 7.8 and 11.2, respectively
2. 6.4 and 11.2, respectively
3. 7.8 and 0, respectively
4. 6.4 and 0, respectively
Question 3
2. cout << values[6]; since indexing in arrays start with 0. So the index of the seventh element will be 7-1 = 6. Therefore, seventh element is values[6]
Question 4
Answer is: 6.4 and 0, respectively
The indexing in array start at 0.Therefore, the length[1] will be the second element in the array.
Comments
Leave a comment