請問如何將指標傳入副程式內?
例如:
program main
implicit none
integer, pointer :: ptr(:)
call sub(ptr)
write(*,*) ptr
end
subroutine sub(ptr)
implicit none
integer, pointer :: ptr(:)
allocate( ptr(3) )
ptr = (/1,2,3/)
end
我目的是希望能在副程式內,宣告陣列大小並賦予值。
最後並回傳到主程式,但無法成功。
嘗試了一下發現副程式接收的好像是指標所指的東西,而非指標本身。
請教各位高手,這該如何改寫,謝謝