Read the program below and answer the questions that follow. #include <stdio.h>
ID: 3642007 • Letter: R
Question
Read the program below and answer the questions that follow.#include <stdio.h>
int mystery(int x[], int size);
main()
{
int a[3] = {22, 11, 33}, b;
b = mystery(a, 3);
printf("a[0] = %d, b = %d ", a[0], b);
}
int mystery(int x[], int size)
{
int i, temp = x[0];
for (i=1; i<size; i++)
{
temp += x[i];
if (x[0] < x[i])
x[0] = x[i];
}
return temp;
}
a. During the execution of the program above, what variables exist in memory just before the statement "return temp;" executes, and what are their values? The values of pointer variables can be specified either by using the address operator & or by assigning names to represent addresses in memory diagrams.
b. During the execution of the program above, what variables exist in memory just before the statement "printf("a[0] = %d, b = %d ", a[0], b);" executes, and what are their values?
c. Exactly what will be displayed when this program executes?
Explanation / Answer
a) an int array a exists - a[3] a[0] = 33 a[1] = 11 a[2] = 33 an int b = undefined an int i = 2 an int temp = 66 b) an int array a exists - a[3] a[0] = 33 a[1] = 11 a[2] = 33 an int b = 66 c) a[0] = 33, b = 66
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.