title: Fortran 90 - segmentation fault
body: <p>I am making a program that converts a decimal integer into its binary representation. Here is my code:</p>
  
  <pre><code>program test
  implicit none
  integer, dimension(:), allocatable :: binary
  integer :: decimalnum, i, initvalue
  
  print*, "Enter decimal number to convert: "
  read*,initvalue
  
  decimalnum = initvalue
  i = 0
  
  do while (decimalnum &gt; 0)
      if (MOD(decimalnum,2)==0) then
          binary(i) = 0                  ! this is as far as the program executes up to 
          decimalnum = decimalnum / 2
          i = i + 1
      else if (MOD(decimalnum,2)==1) then
          binary(i) = 1
          decimalnum = (decimalnum -1) / 2
          i = i + 1
      end if
  end do
  end program test
  </code></pre>
  
  <p>At the marked point, it returns the error <code>Segmentation fault</code> and exits with code 139.</p>
  
  <p>Why does this happen? </p>
  
  <p>Thanks in advance.</p>