1 int multiplier= 1000; 2 3 int podraceWinnings (int place) 4 int winnings = 0;
ID: 3727769 • Letter: 1
Question
1 int multiplier= 1000; 2 3 int podraceWinnings (int place) 4 int winnings = 0; winnings = (10 - place) * multiplier; return Winnings 6 8 9 10 int main (void) [ int prizeAmt 0; int finish5; int multiplier 106 12 13 14 15 16 17 18 19 prizeAmt = podraceWinnings(finish); printf("Multiplier-%d ", multiplier); printf("Prize Amount: %d ", prizeAnt); return ; 2. Given the code in question 1, and assuming static scoping is used, draw the stack of dictionaries for the symbol table at the specified line. For each dictionary entry, include the identiher name and line number 1. at line 7 2. at line 16 3. Repeat question 2 using dynamic scoping instead of static. 4. What is printed by the code in question 1, if the code uses 1. static scoping? 2. dynamic scoping?Explanation / Answer
Solution:
2)
For line 7
identifier name = winnings
the output using static scoping= 5000 will be returned
line 16 is modifying the last value of the winnings variable
for line 16
identifier name = multiplier
this variable will be extracted from line 13 in case of static scoping
output: 100 will be printed
3)
For line 7
identifier name = winnings
line 16 is modifying the last value of the winnings variable, here in case of dynamic scoping the value of multiplier will be extracted from last caller function which is 100
So the output:
500 will be returned
for line 16
identifier name = multiplier
this variable will be extracted from line 13 in case of dynamic scoping
output: 100 will be printed
4)
Static scope:
Multiplier = 100
Prize Amount: 5000
Dynamic scope:
Multiplier = 100
Prize Amount: 500
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.