在 Fortran 中,是否可以定义一个返回多个值的函数,如下所示?
[a, b] = myfunc(x, y)
最佳答案
这取决于...使用函数
,不可能有两个不同的函数结果。但是,您可以从该函数返回一个长度为 2 的数组。
function myfunc(x, y)
implicit none
integer, intent(in) :: x,y
integer :: myfunc(2)
myfunc = [ 2*x, 3*y ]
end function
如果您需要两个不同变量的两个返回值,请使用子例程
:
subroutine myfunc(x, y, a, b)
implicit none
integer, intent(in) :: x,y
integer, intent(out):: a,b
a = 2*x
b = 3*y
end subroutine
关于fortran - 返回多个值的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37120263/