Are any modifications to the value of a dynamically scoped variable persistent even after the function (in which modifications were made) returns? For example, in the following code (assuming dynamic scoping):
void weird_function (int i)
{
i = 5;
return;
}
int main (void)
{
int i = 4;
weird_function(i);
printf(“%d\n”, i);
return 0;
}
ignoring call-by-value semantics; when the control returns to main after calling weird_function, would the variable i (which is dynamically scoped) contain 4 or 5?
In other words, would the dynamically scoped variables be allocated on heap or do they live in the stack frame of current function? Do dynamically scoped variables essentially act like global variables in this particular regard?