016. An array of character variables has elements of the same length#

topic: Character variables

char-array.f90 | | Godbolt Compiler Explorer logo | Fortran logo#
character(len=5) :: w(3)

! This is invalid and would raise a compilation error:
! w = ["one", "four", "seven"]

w = ["one  ", "four ", "seven"]  ! same as below
w = [character(5) :: "one", "four", "seven"] 

print *, w

end
Output1#
 one  four seven


1

Compiled using GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 with no flags