1 / 12

實際參數 (Actual parameter) 與形式參數 (Formal parameter) 主程式的參數稱為實際參數,副程式的參數稱為形式參數 實際參數與形式參數的 個數 必須相同,且 資料型態 也需一致。 實際參數的形式參數的名稱

參數. 實際參數 (Actual parameter) 與形式參數 (Formal parameter) 主程式的參數稱為實際參數,副程式的參數稱為形式參數 實際參數與形式參數的 個數 必須相同,且 資料型態 也需一致。 實際參數的形式參數的名稱,可以相同也可以不同。. 參數的傳遞 . 傳值呼叫 (Call-by-Value) 傳址呼叫 (Call by Address) 傳名呼叫 (Call by Name) 傳值兼結果呼叫 (Call by Value Result) Call by Value Restore. 傳值呼叫 (Call-by-Value).

roza
Download Presentation

實際參數 (Actual parameter) 與形式參數 (Formal parameter) 主程式的參數稱為實際參數,副程式的參數稱為形式參數 實際參數與形式參數的 個數 必須相同,且 資料型態 也需一致。 實際參數的形式參數的名稱

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 參數 • 實際參數(Actual parameter)與形式參數(Formal parameter) • 主程式的參數稱為實際參數,副程式的參數稱為形式參數 • 實際參數與形式參數的個數必須相同,且資料型態也需一致。 • 實際參數的形式參數的名稱,可以相同也可以不同。

  2. 參數的傳遞 • 傳值呼叫(Call-by-Value) • 傳址呼叫(Call by Address) • 傳名呼叫(Call by Name) • 傳值兼結果呼叫(Call by Value Result) • Call by Value Restore

  3. 傳值呼叫(Call-by-Value) • 主程式呼叫副程式時,只將實際參數的值傳給副程式之形式參數,所以實際參數與形式參數之位址不相同。 • 副程式執行時,形式參數之值變動並不會影響主程式之參數值。

  4. 傳址呼叫(Call by Address) • 主程式呼叫副程式時,將主程式之參數位址傳給副程式之對應參數。 • 副程式執行時,因主程式之實際參數與副程式之形式參數位址相同。

  5. 傳名呼叫(Call-by-Name) • 主程式呼叫副程式時,除了把實際參數之名稱傳給副程式外,並取代副程式中所有相對應之參數名稱。 • 主程式的實際參數與副程式之形式參數有相同的位址。

  6. 傳值兼結果呼叫 • 主程式呼叫副程式時,將主程式之參數值傳給副程式之形式參數。 • 副程式執行完成後,將形式參數之結果值傳給對應的實際參數。

  7. 遞迴(Recursion) • 定義 • 在程式(或程序)中,若有直接或間接呼叫程式(或程序)本身的執行流程者,稱之為遞迴(Recursion) • 自己呼叫自己。

  8. 階層(N!) • 階層(N!) procedure FACT (N) if N =1 then return (1) else return (N*FACT(N-1)) end if end

  9. Binomial Coefficient • Binomial Coefficient Procedure BINOMIAL(n,m) if (m=0) or (m=n)then return(1) else return (BINOMIAL (n-1,m)+ BINOMIAL(n-1,m-1)) end if end

  10. 費氏級數(Fibonacci Number) • 費氏級數 procedure FIB (N) if (N=0) or (N=1) then return(N) else return (FIB(N-1)+ FIB(N-2)) end FIB

  11. Ackermann’s Function • Ackermann’s Function Procedure Ack(m,n) If m =0 then return (n+1) Else if n=0 then return (Ack (m-1,1)) else return (Ack (m-1,Ack(m,n-1))) End Ack.

More Related