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      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Fortran中的指针是一种特殊的变量,它可以指向其他变量或数组的地址。通过使用指针,我们可以在程序中动态地访问和修改内存中的数据。在Fortran中,指针的声明和使用需要使用特定的语法。 在引用\[1\]中的示例中,我们可以看到如何声明和使用指针。首先,通过声明`integer, pointer :: p`,我们声明了一个指向整数的指针变量p。然后,通过`p=>a`,我们将指针p指向变量a。这样,我们就可以通过指针p来访问和修改变量a的值。 在引用\[2\]中的示例中,我们展示了如何使用指针来访问数组。通过声明`integer, pointer :: pa(:)`,我们声明了一个指向整数数组的指针变量pa。然后,通过`pa=>a`,我们将指针pa指向数组a。这样,我们就可以通过指针pa来访问和修改数组a的元素。我们还展示了如何使用指针来访问数组的部分元素,例如`pa=>a(1:3)`表示指针pa指向数组a的前三个元素。 在引用\[3\]中的示例中,我们展示了如何使用一些特殊的指针操作。通过`nullify(pa)`,我们将指针pa设置为空指针。然后,通过`associated(pa)`,我们可以检查指针pa是否与任何变量关联。在这个例子中,我们还展示了如何将指针指向一个整数变量,例如`pa=>a`。 总之,Fortran中的指针是一种强大的工具,可以用于动态地访问和修改内存中的数据。通过使用指针,我们可以更灵活地处理数组和变量。 #### 引用[.reference_title] - *1* [Fortran学习15:指针1](https://blog.csdn.net/faltas/article/details/127246050)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [Fortran笔记,指针-Part1](https://blog.csdn.net/qq_21091051/article/details/122909692)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值