0

It is clear to my what pass by value and pass by reference mean, but what happens in the opposite direction ?

e.g:

subroutine get_flux(flux,ngrid,u,a,c)
implicit none
    double precision, dimension(1:ngrid), intent(in) :: u
    double precision, intent(in) :: a,c
    integer, intent(in) :: ngrid
    double precision, intent(out) :: flux
    flux = a*u*(1-u)**c 
end subroutine

if i call this subroutine by

double precision, dimension(1:ngrid) :: flux
double precision, parameter :: a = 1, c = 5
double precision, dimension(1:ngrid) :: u(:) = 2
call get_flux(flux,ngrid,u,a,c)       

Does the subroutine passes a reference back, or a copy of the array ?

1 Answer 1

3

I'm not aware of any programming language which, when passing an argument in one direction by reference does not pass the same argument by reference in the other. Certainly in Fortran arguments appear to be passed by reference in both directions. I write appear to be because the standard does not require that arguments be passed by reference, just that the program behaves as if they are. In general that is, sometimes compilers will make copies, perhaps if an array section is passed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.