Memory Diagram Practice
In groups of about four, take a few minutes to draw a memory diagram for the following program. When you reach points marked "Return to discuss", stop what you're doing and wait for everyone else to catch up to that point. Then, compare answers as a group. If there are any disagreements, try to resolve them and reach the correct answer!
#include <iostream>
#include <algorithm>
float max(float lhs, float rhs) {
if (lhs > rhs) {
return lhs;
} else {
return rhs;
}
}
int sum(int a, int b) {
int sum;
sum = 0;
sum += a;
sum += b;
return sum;
}
int main() {
int x = 40;
int y = 2;
// <--- Return to discuss!
float percent = max(x, y);
// <--- Return to discuss!
percent /= sum(x, y);
std::cout << percent << std::endl;
return 0;
}
Do we have to run the program all the way to completion?
No, just to the points marked "Return to discuss". The goal is to practice drawing memory diagrams, not to run the program all the way through.
(When logged in, completion status appears here.)