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

Read the program below and answer the 3 questions that follow. #include <stdio.h

ID: 3533418 • Letter: R

Question

Read the program below and answer the 3 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;

}

1. 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.

2. 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?


3. Exactly what will be displayed when this program executes?  

Explanation / Answer

before return

temp=66

a[0]=33;

a[1]=22;

a[2]=33;

before print

temp=66

a[0]=33;

a[1]=22;

a[2]=33;

it will display

33, 66