fortran中定义常数型变量
fortran中定义常数型变量
001、
[root@localhost test]# ls test01.f90 [root@localhost test]# cat test01.f90 program test01_fortran implicit none integer :: a = 5 integer, parameter :: b = 5 ## 定义一个常数型变量 a = 10 print *, "a = ", a end program test01_fortran [root@localhost test]# gfortran test01.f90 -Wall -O2 -o kkk [root@localhost test]# ls kkk test01.f90 [root@localhost test]# ./kkk a = 10

。
002、
[root@localhost test]# ls test01.f90 [root@localhost test]# cat test01.f90 program test01_fortran implicit none integer :: a = 5 integer, parameter :: b = 5 a = 10 b = 10 ## 尝试对常数型变量进行修改,无法编译 print *, "a = ", a end program test01_fortran [root@localhost test]# gfortran test01.f90 -Wall -O2 -o kkk test01.f90:9:8: 9 | b = 10 | 1 Error: Named constant ‘b’ in variable definition context (assignment) at (1)

。

浙公网安备 33010602011771号