I'm new to Fortran, and sorry for this noobish question, I didn't find an answer for it. In the code:
integer ( kind = 4 ) k
integer ( kind = 4 ) v(k)
integer ( kind = 4 ) list(*)
What does (k) and (*) do in the second, third line?
Thanks
The first integer, k
is a scalar. The second integer v(k)
is an array v
with k
elements. The last integer list(*)
an assumed size array that is a dummy argument to a procedure. Its length (number of elements) will be determined by the actual argument passed to the procedure.
Note that kind = 4
is not portable and you should instead use the intrinsics kind()
or selected_int_kind()
to specify the size of your integers.
Complementing the answer of @casey:
The definition of
INTEGER(KIND=4) list(*)
is only valid as definition of a dummy argument. Though, you can define this list with the help of a constant as a named constant (specified by the PARAMETER
keyword):
INTEGER(KIND=4), PARAMETER :: list(*) = [1,2,3,4,5]
In this case, this is called an implied-shape array (5.3.8.6) which gets its length implicitely from the constant array.