Memory Diagram Practice (optional)
In groups of 2-3, 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>
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;
}
(When logged in, completion status appears here.)