I encountered this problem while solving a practice test
Consider the following code written in a pass-by-reference language like
FORTRAN and these statements about the code
subroutine swap(ix,iy)
it = ix
ix = iy ! line L1
iy = it ! line L2
end
program main
ia = 3
ib = 8
call swap (ia, ib+5)
print *, ia, ib
end program
Statements:
- The compiler will generate code to allocate a temporary nameless cell,
initialize it to 13, and pass the address of the cell swap - On execution the code will generate a runtime error on line L1
- On execution the code will generate a runtime error on line L2
- The program will print 13 and 8
- The program will print 13 and -2
Which of the above the above statement(s) is/are correct.
I think S1 and S4. Could anyone please confirm? TIA
Yes, S1 and S4 are correct.
Also,
S0a: The file is not compilable as is because the L1: and L2: are syntax errors. 🙂
S0b: Strictly speaking, speaking of FORTRAN as a pass-by-reference language is incorrect:
The name of the language is Fortran
Pass by reference is an implementation detail that is not specified in the standard. Copy-in, copy-out is another possible implementation. Also, some newer Fortran language features (F90+) in practice imply an implementation which is neither pass-by-reference nor copy-in-copy-out. See e.g. pointer as a dummy argument and http://software.intel.com/en-us/blogs/2009/03/31/doctor-fortran-in-ive-come-here-for-an-argument/