Question: consider the fallowing code: #include void f1() { int i = 10; int j = 100; printf(f1: i + j = %d , i +
consider the fallowing code:
#include
void f1() {
int i = 10;
int j = 100;
printf("f1: i + j = %d ", i + j);
}
void f2() {
int m;
int n;
printf("f2: m + n = %d ", m + n);
}
int main () {
int i = 5;
int j = 6;
f1();
f2();
printf("main: i + j = %d ", i + j);
}
- Run the code and observe its output. Draw a memory diagram indicating the stack's contents just before f2 () returns. (Use the stack model described above, remember to ignore printf statements). Confirm that our stack model accurately represents the program's behavior.
- change the program so f2 () is called before f1 (). How does the program output change?
- Revert so that f1 () is called first. Then change the program so that int m is initialized to 3 in its declaration in f2(). Does our memory stach model still accurately represent the program behavior?. If not, can you guess what the compiler is doing differently?
- Revert so int m in not initialized, and int n = 4. Does our stack model still accurately represent the program behavior? If not, can you guess what the compiler is doing differently?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
