010. Fortran arrays can have any lower bound (the default is 1)#

topic: Arrays

Fortran arrays can have any lower bound. The default is 1. Array functions have optional mask arguments to determine the elements used.

array-lbound.f90 | | Godbolt Compiler Explorer logo | Fortran logo#
integer :: v(-1:1) = [1, -2, 3]

print *, lbound(v), ubound(v), size(v)  ! -1 1 3
print *, sum(v)  ! 2
print *, sum(v,mask=v>0)  ! 4 -- sum excludes -2

end
Output1#
          -1           1           3
           2
           4


1

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