fortran指针

A pointer is a
variable that has the pointer attribute.A pointer is associated with a target by allocation
or pointer assignment
具有target属性的变量,可以用指针指向该变量

program main
implicit none
integer,pointer ::a=>null(),b=>null()
integer,target ::c
integer ::d
  c=1
  print*,associated(a)
  a=>c
  c=2
  b=>c
  d=a+b
  print*,associated(a)
  print*,a,b,c,d
end



输出 2 2 2 4

The associated intrinsic returns the association status of a pointer variable
associated返回T or F,如果指针已与变量关联返回T,否则返回F


integer , pointer :: a=>null(),b=>null()
allocate(a)
a = 1
如果我们没有allocate a那么对a进行赋值是非法的

program main
implicit none
integer,pointer ::a=>null(),b=>null()
integer,target ::c
integer ::d
  allocate(a)
  allocate(b)
  a=100
  b=200
  print*,a,b
  c=1
  a=>c
  c=2
  b=>c
  d=a+b
  print*,a,b,c,d
end


输出100 200
2 2 2 4

ALLOCATE ( allocation-list [ , STAT = stat-variable ] )

If the STAT= specifier is present, successful execution of the ALLOCATE statement causes the stat-variable to
become defined with a value of zero. If an error condition occurs during the execution of the ALLOCATE
statement, the stat-variable becomes defined with a processor-dependent positive integer value.


References
Ian Chivers / Jane Sleightholme 
Introduction to Programming with Fortran- With Coverage of Fortran 90, 95, 2003, 2008 and 77      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值