Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. What is stored in alpha after the following code executes? int alpha[5] = {0}

ID: 3644213 • Letter: 2

Question

2. What is stored in alpha after the following code executes?

int alpha[5] = {0};
int j;
for (j = 0; j < 5; j++)
{
alpha[j] = 2 * j;
if (j % 2 == 1) //see if j is an even number
alpha[j - 1] = alpha[j] + j;
}
alpha = {0, 2, 4, 6, 8}
alpha = {0, 2, 9, 6, 8}
alpha = {0, 3, 4, 7, 8}
alpha = {3, 2, 9, 6, 8}

3. Suppose that gamma is an array of 50 components of type int and j is an int variable. Which of the following for loops sets the index of gamma out of bounds?
for (j = 0; j < 50; j++)
for (j = 1; j <50; j++)
for (j = 0; j <=50; j++)
for (j = 0; j <=49; j++)

4. Consider the following declaration:
int alpha[3];
Which of the following input statements correctly inputs values into all the array elements of alpha?
cin >> alpha >> alpha >> alpha;
cin >> alpha[0] >> alpha[1] >> alpha[2];
cin >> alpha[1] >> alpha[2] >> alpha[3];
cin >> alpha

5. Given the function prototype void strange(int a, int b);
And the following declaration,
int alpha[10];
int beta[10];
Which of the following is a valid call to the function strange?
strange(alpha[0], alpha[1]);
strange(alpha, beta);
strange(alpha[0], beta);
strange(alpha, beta[0]);

6. Consider the following statement:
int alpha[25][10];
Which of the following statements about alpha is true?
Rows of alpha are numbered 0...24 and columns are numbered 0...9.
Rows of alpha are numbered 0...24 and columns are numbered 1...10.
Rows of alpha are numbered 1...24 and columns are numbered 0...9.
Rows of alpha are numbered 1...25 and columns are numbered 1...10.

7. After the following statements execute, what are the contents of matrix?

int matrix[4][3] = {0};
int j, k;
for (j = 0; j < 4; j++)
for (k = 0; k < 3; k++)
matrix[j][k] = 2 * j + k;
0 2 4
1 3 5
2 4 6
3 5 7
0 1 2
1 2 3
2 3 4
3 4 5
0 2 4
2 4 6
4 6 8
6 8 10
0 1 2
2 3 4
4 5 6
6 7 8

Explanation / Answer

2. alpha = {0, 2, 4, 6, 8}

3. for (j = 0; j <=50; j++)

4. cin >> alpha[0] >> alpha[1] >> alpha[2];
cin >> alpha[1] >> alpha[2] >> alpha[3];

5. strange(alpha[0], alpha[1]);

6. Rows of alpha are numbered 0...24 and columns are numbered 0...9

7. 0 1 2
2 3 4
4 5 6
6 7 8

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote