Hi all !!
I am new to Fortran. Please see the following code:
program exp_realloc
implicit none
integer,allocatable,dimension(:,:):: array
integer::i,j
allocate(array(3,3))
write(*,*)size(array,1)," ",size(array,2)
do i=1,3
do j=1,3
array(i,j)=i*j
write(*,*)array(i,j)
enddo
write(*,*)
enddo
CALL func(array)
end program exp_realloc
subroutine func(array)
integer,dimension(:,:),intent(in)::array
integer::i,j
write(*,*)"********* Inside subroutine **********"
write(*,*)size(array,1)," ",size(array,2)
write(*,*)array(1,1)
write(*,*)array(1,2)
write(*,*)array(2,1)
do i=1,3
do j=1,3
write(*,*)array(i,j)
enddo
enddo
end subroutine func
The output is:
3 3
1
2
3
2
4
6
3
6
9
********* Inside subroutine **********
131097 1
Segmentation fault
Two questions:
- Why is the size of array not being printed correctly in the subroutine?
- Why the segmentation fault?
Thank you in advance !!