! ------------------------------------------ ! Example program ! ! Demonstrates how the k in the subroutine ! is *not* the same k as in the main program ! ! Warning: The program "works", but not quite the way it ! was supposed to. If you use a compiler option ! that traps unitialised variables you might find the ! mistake already at compilation time. ! ------------------------------------------ program test implicit none integer:: i,k=100 ! initialise k do i = 1, 5 call addone print*,'k in main routine = ',k end do end program test subroutine addone integer:: k k = k + 1 ! this print statement is added to see what k is print*,'k in subroutine = ',k end subroutine addone