FORTRAN 77 Language Reference


The CHARACTER statement specifies the type of a symbolic constant, variable, array, function, or dummy function to be character.

Optionally, it initializes any of the items with values and specifies array dimensions.

CHARACTER [* len[,]] v [* len /c/]]




Name of a symbolic constant, variable, array, array declarator, function, or dummy function  


Length in characters of the symbolic constant, variable, array element, or function  


List of constants for the immediately preceding name  


Each character occupies 8 bits of storage, aligned on a character boundary. Character arrays and common blocks containing character variables are packed in an array of character variables. The first character of one element follows the last character of the preceding element, without holes.

The length, len must be greater than 0. If len is omitted, it is assumed equal to 1.

For local and common character variables, symbolic constants, dummy arguments, or function names, len can be an integer constant, or a parenthesized integer constant expression.

For dummy arguments or function names, len can have another form: a parenthesized asterisk, that is, CHARACTER*(*), which denotes that the function name length is defined in referencing the program unit, and the dummy argument has the length of the actual argument.

For symbolic constants, len can also be a parenthesized asterisk, which indicates that the name is defined as having the length of the constant. This is shown in Example 5 in the next section.

The list c of constants can be used only for a variable, array, or array declarator. There can be only one constant for the immediately preceding variable, and one constant for each element of the immediately preceding array.


Example 1: Character strings and arrays of character strings:

       CHARACTER*17 A, B(3,4), V(9) 
       CHARACTER*(6+3) C 

The above code is exactly equivalent to the following:

       CHARACTER A*17, B(3,4)*17, V(9)*17 
       CHARACTER C*(6+3) 

Both of the above two examples are equivalent to the nonstandard variation: @

       CHARACTER A*17, B*17(3,4), V*17(9)	 nonstandard

There are no null (zero-length) character-string variables. A one-byte character string assigned a null constant has the length zero.

Example 2: No null character-string variables:

       CHARACTER S*1
       S = ''

During execution of the assignment statement, the variable S is precleared to blank, and then zero characters are moved into S, so S contains one blank; because of the declaration, the intrinsic function LEN(S) will return a length of 1. You cannot declare a size of less than 1, so this is the smallest length string variable you can get.

Example 3: Dummy argument character string with constant length:

       CHARACTER A*32 

Example 4: Dummy argument character string with length the same as corresponding actual argument:

       CHARACTER A*(*) 

Example 5: Symbolic constant with parenthesized asterisk:

       CHARACTER *(*) INODE 
       PARAMETER (INODE = 'Warning: INODE corrupted!')

The intrinsic function LEN(INODE) returns the actual declared length of a character string. This is mainly for use with CHAR*(*) dummy arguments.

Example 6: The LEN intrinsic function:

       CHARACTER A*17
       A = "xyz"
       PRINT *, LEN( A )

The above program displays 17, not 3.