I am trying to understand some Fortran code. There is a subroutine which takes a 2D array as input. Then this subroutine is called from somewhere else, but is passed the first element of a 2D array instead of the array itself. However, the subroutine seems to treat this input as if it were just the 2D array itself and is able to access all of its elements. This makes it seem like the subroutine actually accepts a pointer to a scalar, like how you can pass arrays in C/C++.
I have made a small example that demonstrates what I mean:
program main
dimension k(2, 2);
k(1, 1) = 1; k(1, 2) = 2
k(2, 1) = 4; k(2, 2) = 3
call test(2, k(1, 1))
end program
subroutine test(n, k)
dimension k(n, n)
do i=1, n
write(*, '(2(I1 X))') (k(i,j), j=1,n)
end do
end subroutine test
This program outputs the following:
1 2
3 4
Can someone explain this to me?