Scope of variables in Fortran

Categories: Code
Fortran has an option of local variables called SAVE. If this option is added, its value will be kept until the end of program. To clarify, let's say if the code is like the following: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 program main integer :: a = 1 write(*,*) "a=",a call add1(a) write(*,*) "a=",a call add1(a) write(*,*) "a=",a end program subroutine add1(a) integer,save :: b integer :: a write(*,*) "b=",b b=1 a = a+b b = b+1 end subroutine No matter how do you compile it, the output will be like the following:

Read More →