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