023. elemental
functions broadcast arguments#
topic: Procedures
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
12
12 15
12 20
Elemental functions broadcast arguments. Neat Fortran feature!
— FortranTip (@fortrantip) December 19, 2021
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
- 1
Compiled using
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
with no flags