Character variables can be declared in a similar way to numeric types using a CHARACTER statement. CHARACTER variables can
A simplified syntax follows,
< type >[(LEN=< length-spec >)] [,
< attribute-list >] [:
:
] < variable-list > [ =< value > ]
If < attribute-list > or =< value > are present then so must
be :
:
.
The following are all valid declarations,
CHARACTER(LEN=10) :: name CHARACTER :: sex CHARACTER(LEN=32) :: str
In the same way as the DIMENSION attribute was overridden in the example of Section 5.4 so can the string length declaration (specified by LEN=); this is achieved using the * notation. If a DIMENSION specifier is present it can also be overridden. The length specifier must come after the dimension if both are being overridden.
CHARACTER(LEN=10) :: name, sex*1, str*32 CHARACTER(LEN=10), DIMENSION(10,10) :: tom(10)*2, dick, harry(10,10,10)*20 CHARACTER, POINTER :: P2ch
The first line is exactly the same as the previous declaration.
There is a substantial difference between a character variable of 10 characters (CHARACTER(LEN=10) or CHARACTER*10) and an array of 10 elements; the first is scalar and the second is non-scalar.
Other attributes can be added in the same way as for numeric types (see Section 5.4).
Return to corresponding overview page