023. elemental functions broadcast arguments#

topic: Procedures

elemental.f90 | | Godbolt Compiler Explorer logo | Fortran logo#
print *, area(3, 4)  ! 12
print *, area(3, [4, 5])  ! 12 15
print *, area([3, 4], [4, 5])  ! 12 20

contains

integer elemental function area(length, width)
   integer, intent(in) :: length, width
   area = length*width
end function area

end
Output1#
          12
          12          15
          12          20


1

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