Local Arrays

In addition to formal arguments, we can declare variables in a function or a subroutine. The scope rules state that these locally declared variables and parameters can only be used with that function or subroutine. Therefore, these variables are called local variables.

Arrays can also be declared in a function or subroutine. Since they are declared and used locally and are not formal arguments, local arrays cannot use INTENT(). So, the only one thing we have to know is the way of writing the extent in a local array declaration. It turns out that the extent of a local array is more flexible than that of a global array. Here are the rules:

From the above discussion, we learn that local array provides an easy way for us to declare arrays locally rather than passing arrays around though formal argument which could cause a large number of formal arguments in a function or subroutine call. Since the extent of a local array could use formal arguments as well as constants, its size is flexible and determined when the function or subroutine is called.