Just need the answer to b solved: In the above code, suppose we remove the \"sta
ID: 3585258 • Letter: J
Question
Just need the answer to b solved: In the above code, suppose we remove the "static" from "static int F=0;" and just have "int F=0;" in myfunc(). Explain how this may affect the program and what might be the new output.
[15 points] Show the memory image of the following program when it is executed (Specifically show where the variables reside, and how their values change). Also give the output of the program. a. #include (10pt) #include int myfunc (int E) int A, B-6; int main(int argc, char *argv[]) Variable name Memory Image int C, D; A = 4; C = myfunc ( 5 ) ; D = myfunc ( 7 ); printf ("A=%d B-2d C=2d D-%d ", STACK A, B, C, D); return 0 HEAP int myfunc (int E) static int F=0; F=F+E; return F Un-Init Data Init Data OUTPUT: (5pt) TEXT b. [5pt] In the above code, suppose we remove the "static" from "static int F-0; " and just have "int F-0;" in myfunc). Explain how this may affect the program and what might be the new output.Explanation / Answer
Solution:
b)
If we remove the static int F= 0; to int F= 0; then the memory will be allocated in the stack area and the scope of this variable F will be limited to only, so each time the function is called memory of F in the stack will be created and as the function ends it will be destroyed.
so the output will be
4, 6, 5, 7
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.