主程序中調(diào)用帶初始化變量的子程序時(shí),需要注意使用相同類型的變量來(lái)給子程序初始化參數(shù),否則就會(huì)報(bào)錯(cuò)。如示例 3 中所示,子程序中所定義的參數(shù) x 和 y 為實(shí)數(shù)、參數(shù) m 和 n 為整數(shù)。主程序中調(diào)用時(shí)傳遞的變量值也是對(duì)應(yīng)的實(shí)數(shù)和整數(shù),具體如下表所示。
!!! 示例 3 program stest3 implicit none real z integer n z = 200.0 n = 21 call subr3(10.0, z**2, 100, n*5+1) end program stest3
subroutine subr3(x, y, m, n) implicit none real x, y integer m, n print *, x, y, m, n end subroutine subr3
更多建議: