Likely default value of an undefined variable

It’s fairly easy to test what different compilers do to uninitialized variables:

program main
    implicit none

    real :: x

    print *, x
end program

Then you can try different compilers and flags. For example:

$ gfortran main.f90 && for i in {1..10}; do ./a.out; done
   5.17461830E-24
   5.84620817E-17
   1.06416293E-03
  -1.72170103E-02
   1.18819388E+23
   6.59463023E-20
  -1.98622284E-30
  -6.92440164E+12
  -2.12326761E-30
   106597.242
$ ifort main.f90 && for i in {1..10}; do ./a.out; done
  0.0000000E+00
  0.0000000E+00
  0.0000000E+00
  0.0000000E+00
  0.0000000E+00
  0.0000000E+00
  0.0000000E+00
  0.0000000E+00
  0.0000000E+00
  0.0000000E+00

Interestingly, when I use optimization, my currently installed gfortran version seems to use zero in this case:

$ gfortran -O3 main.f90 && for i in {1..10}; do ./a.out; done
   0.00000000    
   0.00000000    
   0.00000000    
   0.00000000
   0.00000000    
   0.00000000
   0.00000000    
   0.00000000
   0.00000000    
   0.00000000

I read a quote once that was something like this: “If you have undefined behaviour in your application it might work just fine, it might erase your hard drive or it might start playing Quake on its own”. That is of course highly unlikely in this case, but the point is that you simply don’t know what you’ll get.