Fortran parameter
In Fortran, a parameter is a named constant that is assigned a value that cannot be changed during the execution of the program. It is declared using the parameter
keyword followed by the name of the constant and its value.
For example, consider the following code:
program example
implicit none
integer, parameter :: n = 10
real, parameter :: pi = 3.14159
print *, "The value of n is:", n
print *, "The value of pi is:", pi
end program example
In this code, we have declared two parameters n
and pi
. The value of n
is set to 10 and the value of pi
is set to 3.14159. These values cannot be changed during the execution of the program.
When we run the program, it will print the following output:
The value of n is: 10
The value of pi is: 3.14159012
Note that parameters are often used to define physical or mathematical constants that are used throughout the program. They can also be used to simplify the code and make it more readable by replacing hard-coded values with named constants.
相关推荐


















