Value that Fortran assumes for a specific variable

I had a question related to the value that Fortran assumes for a specific variable. Consider the Fortran program in the attached image. In this program, we first declare the variable ryf. Then we do “k” from 1 to 2, “j” from 1 to 2 and “i” from 1 to 2, in order to calculate the value of ryf at the points (i, j, k). Although the program only provides the formula for calculating ryf at points where i<j, Fortran is also calculating ryf at other points (with i>=j). My question is: what calculation is Fortran doing for the variable ryf when i>j and when i=j?

As I understand it, for an uninitialized array the values ​​attached to it depend on the compiler. These values ​​can be zero or any random number.

You could use ryf = 0.0 to initialize

1 Like

Welcome to the forum. A Fortran variable that is not set is undefined. It could be anything, and if you run the same executable repeatedly you may see different results.

To catch the use of uninitialized variables, initialize real variables to signalling NaN and integers to -999 and trap NaNs at run time with


gfortran -g -ffpe-trap=invalid,overflow -finit-real=snan -finit-integer=-999 -fbacktrace a.f90

For Intel Fortran see this.

3 Likes