- 指针可以看作一种数据类型
- 指针存储与之关联的数据的内存地址
- 变量指针:指向变量
- 数组指针:指向数组
- 过程指针:指向函数或子程序
- 指针状态
integer, pointer::p1=>null()
!或者
nullify(p1)
- 指针操作
- 指向
- 将变量、数组、过程或指针的内存地址以及其他信息(数组上下界、过程接口等)赋值给指针
- 赋值
- 将非过程的量所关联的值赋值到指针所关联的地址。涉及到的所有指针必须已经关联到足够的内存空间
associated(pointer) !是否已经有关联
associated(target, pointer) !这两个是否有关联
! A fortran95 program for G95
! By WQY
program test
implicit none
integer, target::a=1
integer, pointer::p=>null()
print*, associated(p)
p=>a
print*, associated(p)
print*, associated(p, a)
pause
end program
! A fortran95 program for G95
! By WQY
program test
implicit none
integer, target::a(2, 3)=999
integer, pointer::p(:, :)=>null()
print*, associated(p)
p=>a
print*, associated(p)
print*, associated(p, a)
pause
end program
! A fortran95 program for G95
! By WQY
program test
use m
integer::a=1
procedure(pro), pointer::p
interface
subroutine pro(a)
integer a
end subroutine
end interface
p=>sub
call p(a)
pause
end program
module m
contains
subroutine sub(a)
integer a
print*, "sub:", a
end subroutine sub
end module