主程序中調(diào)用帶初始化變量的子程序時,需要注意使用相同類型的變量來給子程序初始化參數(shù),否則就會報錯。如示例 3 中所示,子程序中所定義的參數(shù) x 和 y 為實數(shù)、參數(shù) m 和 n 為整數(shù)。主程序中調(diào)用時傳遞的變量值也是對應(yīng)的實數(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
調(diào)用語句 | 子程序語句 | 數(shù)值類型 |
---|---|---|
10.0 | x | 實數(shù) |
z**2 | y | 實數(shù) |
100 | m | 整數(shù) |
n*5+1 | n | 整數(shù) |
更多建議: