Truncation and Padding

String variables are rarely "full", i.e. they rarely contain a string of the maximum length. Fortran pads string variables with spaces to fill the unused elements in the string. Hence, the following two statements are equivalent:

        name = 'Alfred E. Neumann'
        name = 'Alfred E. Neumann                       '
        

Caution

If we attempt to assign a string that is too large for the variable, it will be truncated. This can be disastrous for some programs!
        module constants
            integer, parameter :: MAX_NAME_LENGTH=10
        end module
        
        program string_example
            implicit none
            
            character(MAX_NAME_LEN) :: name
            
            name = 'Alfred Hitchcock'
            print *, name
        end program
        

Output:

        Alfred Hit