Static Scope 1.3 What is the output? Make certain you show the output in the cor
ID: 3871578 • Letter: S
Question
Static Scope
1.3 What is the output? Make certain you show the output in the correct order.
void main()
{
int m = 100;
int i = 101;
int c = 102;
int k = 103;
int e = 104;
int y = 105;
subA();
print("main", "m=", m, "i=", i, "c=", c, "k=", k, "e=", e, "y=", y);
void subA()
{
int m = 200;
int x = 1;
subB();
print("subA", "m=", m, "i=", i, "c=", c, "k=", k, "e=", e, "y=", y);
void subB()
{
int i = 311;
int c = 312;
m += 20;
x += 5;
k += 10;
subC();
print("subB", "m=", m, "i=", i, "c=", c, "k=", k, "e=", e, "y=", y);
void subC()
{
int c = 402;
int k = 403;
int e = 404;
m += 30;
i += x;
if (x < 10)
subB();
else
subD();
print("subC", "m=", m, "i=", i, "c=", c, "k=", k, "e=", e, "y=", y);
}
}
}
void subD()
{
int y = 505;
m += 50;
i += 50;
k += 50;
e += 50;
print("subD", "m=", m, "i=", i, "c=", c, "k=", k, "e=", e, "y=", y);
}
}
Explanation / Answer
Series of execution starts with main() function
main
int m = 100,
int i = 101,
int c = 102,
int k = 103,
int e = 104,
int y = 105
subA
int m = 200;
int i = 101;
int c = 102;
int k = 103;
int e = 104;
int y = 105;
int x = 1;
subB
int m = 220;
int i = 311;
int c = 312;
int k = 113;
int e = 104;
int y = 105;
int x = 6;
subC
int m = 220;
int i = 317;
int c = 402;
int k = 403;
int e = 404;
int y = 105;
int x = 6;
and back to subB
int m = 240;
int i = 311;
int c = 312;
int k = 413;
int e = 404;
int y = 105;
int x = 11;
now coming to subC
int m = 270;
int i = 322;
int c = 402;
int k = 403;
int e = 404;
int y = 105;
int x = 11;
print now
subD
int m = 320;
int i = 372;
int c = 402;
int k = 453;
int e = 454;
int y = 505;
int x = 11;
Now Printing Output sequence
Line 1: main m = 100 i = 101 c = 102 k = 103 e = 104 y = 105
Line 2: subA m = 200 i = 101 c = 102 k = 103 e = 104 y = 105
Line 3: subB m = 220 i = 311 c = 312 k = 113 e = 104 y = 105
Line 4: subB m = 240 i = 311 c = 312 k = 413 e = 404 y = 105
Line 5: subC m = 270 i = 322 c = 402 k = 403 e = 404 y = 105
Line 6: subD m = 320 i = 372 c = 402 k = 453 e = 454 y = 505
Line # will not be printed, I gave the Line number since it will be easy to understand.
Please rate it if you find the answer is helpful....Thank...:)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.