Derived Types and Allocatable
Allocatable Array
Runtime Size
An allocatable array gets its size at run time with allocate, and is released with deallocate.
Program
Play the program to allocate three slots, fill them, and total them.
allocatable_array.f90
program allocatable_array_demo
implicit none
integer, allocatable :: nums(:)
integer :: i
allocate(nums(3))
do i = 1, 3
nums(i) = i * 10
end do
print '(I0)', sum(nums)
deallocate(nums)
end program allocatable_array_demo
allocatable
`integer, allocatable :: nums(:)` declares without a size.
allocate
`allocate(nums(3))` reserves storage at run time.
deallocate
`deallocate` releases the storage.