[Fortran] 纯文本查看 复制代码
module m
integer,allocatable::n(:)
contains
! 分配
subroutine sub1
allocate(n(3))
end subroutine
! 赋值
subroutine sub2
n=[1,2,3]
end subroutine
! 使用
subroutine sub3
integer i
i=n(2)
print*,i
end subroutine
! 释放
subroutine sub4
deallocate(n)
end subroutine
end module
program test
use m
call sub1
call sub2
call sub3
call sub4
end
[Fortran] 纯文本查看 复制代码
module m
integer,allocatable::n(:)
end module
program test
call sub1
call sub2
call sub3
call sub4
end
! 分配
subroutine sub1
use m
allocate(n(3))
end subroutine
! 赋值
subroutine sub2
use m
n=[1,2,3]
end subroutine
! 使用
subroutine sub3
use m
integer i
i=n(2)
print*,i
end subroutine
! 释放
subroutine sub4
use m
deallocate(n)
end subroutine