019. associate creates an alias for expressions or variables#

topic: Associate

assoc.f90 | | Godbolt Compiler Explorer logo | Fortran logo#
integer, allocatable :: u(:)

u = [4,9]

associate (v => u)
v = v - 2
print *, v  ! 2 7
print *, u  ! 2 7

associate (w => [4, 9])
print *, w

! The following is illegal since `w` is set to a constant expression;
! it will raise a compilation error:
! w = w - 2  

! Need one for each of the `associate`s above
end associate
end associate

end
Output1#
           2           7
           2           7
           4           9


1

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