我有一个 FORTRAN 文件“testValueKeyword.for”包含以下代码
subroutine intersub2(x,y)
integer, value :: x
integer y
x = x + y
y = x*y
print *, 'in subroutine after changing: ', x, y
end subroutine
program testValueKeyword
integer :: x = 10, y = 20
print *, 'before calling: ', x, y
call intersub(x, y)
print *, 'after calling: ', x, y
x = 10
y = 20
call intersub2(x, y)
contains
subroutine intersub(x,y)
integer, value :: x
integer y
x = x + y
y = x*y
print *, 'in subroutine after changing: ', x, y
end subroutine
end program
子例程 intersub 和 intersub2 包含相同的代码,都通过值传递 x 参数,但 intersub2 似乎传递了一个类似于内存地址的大随机整数。运行后我得到不同的 y 值。你能给我解释一下吗?