1. (TCO 1) What is the output of the following C++ code? int list[5] = {0, 5, 10
ID: 3540383 • Letter: 1
Question
1. (TCO 1) What is the output of the following C++ code?
int list[5] = {0, 5, 10, 15, 20};
int j;
for (j = 1; j <= 5; j++)
cout << list[j];
0 5 10 15 20
5 10 15 20 0
5 10 15 20 20
Code contains index out of bounds
int alpha[5] = {0};
int j;
alpha[0] = 5;
for (j = 1; j < 5; j++)
{
if (j % 2 == 0) //see if j is an odd number
alpha[j] = alpha[j - 1] + 2;
else
alpha[j] = alpha[j - 1] + 3;
}
10
13
15
17
Explanation / Answer
1) since list[5] does not exist
Code contains index out of bounds
2) 13
alpha[1] = alpha[0] + 3;
alpha[1] = 5 + 3;
alpha[2] = alpha[1] + 2;
alpha[2] = 8 + 2 = 10
alpha[3] = alpha[2] + 3;
alpha[3] = 10 + 3 = 13;
so alpha[3] contain 13.
3) alpha[3] = 3 + 5 = 8;
alpha[3] = alpha[2] + 3;
alpha[2] = 2+7 = 7;
alpha[3] = 7 + 3 =10;
so alpha[3] will be having value 10.
4)int alpha[] = {3, 5, 7, 9, 11};
5) strange(alpha[0], alpha[1]); // only integers we can pass as values.
6) OPTION C
0 1
1 2
2 3
7) Both (i) and (ii) are correct way of intializing the alpha
8) OPTION A
sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[j][3];
9) an object type.
10) and member variables can be either public or private.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.