fortran语言中save的用法
时间: 2023-11-16 12:05:52 浏览: 90
In Fortran, the "save" keyword is used to declare a local variable as having a static lifetime, meaning that its value is preserved across multiple function calls. This is useful when you need to maintain state information between function calls. Here's an example of how you might use "save" in a Fortran program:
subroutine foo()
integer, save :: count = 0
count = count + 1
write(*,*) 'Count = ', count
end subroutine foo
In this example, the "count" variable is declared with the "save" keyword, which means that its value will persist across multiple calls to the "foo" subroutine. The first time "foo" is called, "count" will be initialized to zero. On subsequent calls, the value of "count" will be incremented and printed to the screen.