申論題內容
三、以下是以 C-like 的語言編寫的一段程式碼,請用以分別解釋如以靜態領域法(Static
scoping)與動態領域法(Dynamic scoping)處理變數範圍的話,程式執行結果分別
為何?(應加以解釋)(10 分)
int x;
Sub1(void)
{ /* start of Sub1 function */
printf('x = %d', x);
} /* end of Sub1 */
Sub2 (void)
{ /* start of Sub2 function */
int x;
x:= 10;
Sub1();
} /* end of Sub2 */
main()
{ /* begin of main function */
x = 15;
Sub2();
} /* end of main */