Allocatable array defined or not

program test
  use ieee_arithmetic, only: ieee_value, ieee_quiet_nan
  real(8) :: x1(5)
  real(8), allocatable :: x2(:)
  allocate(x2(5))
  x1(1) = ieee_value(0d0, ieee_quiet_nan)
  x2(1) = ieee_value(0d0, ieee_quiet_nan)
  print *, x1(2:5)
  print *, x2(2:5)
end program

In the program above, x1(2:5) is undefined, is x2(2:5) undefined or defined as zeros?

I don’t see any fundamental difference from your previous question: Undefined variables

It is a different question. I am uncertain whether assigning value to one element of an allocatable array will make the other elements defined as zeros.

Just use sourced allocation to initialize arrays to zero and don’t worry about it.

allocate(x2(5), SOURCE=0.0d0)
1 Like