Question: User Goals: Solidify understanding of pass - by - value vs pass - by - reference. Apply hand tracing to understand the logic of a

User
Goals:
Solidify understanding of pass-by-value vs pass-by-reference.
Apply hand tracing to understand the logic of a modular program.
Follow the execution of a program through it's function all stack.
Requirements:
For this exercise, you will hand trace provided code, filling values into boxes along the way. You won't write a program, rather, you will study the logic of the provided program and follow it's execution through memory as it updates variables. To get the maximum benefit of this lab, use hand tracing as covered in chapter 3. Don't just type up the program and run it to find the answers (see section 3.10).
int bar(int a)
{
return a *1.5;
}
void foo(int& a)
{
a = bar(a);
}
int spam(int a, int& b)
{
float c = a *.5;
b = a *3;
return c;
}
void eggs(int& a, int& b)
{
int c = a;
a = b;
b = c;
}
void bacon(int a)
{
a =0;
}
void ham(int& a, int b)
{
static int c;
a += c;
b += c++;
}
int main()
{
int x =1, y =2;
X Y
bacon(x);
X Y
foo(y);
X Y
x = spam(x, y);
X Y
eggs(x, y);
X Y
for(int i =0; i <3; i++)
ham(x, y);
X Y

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!