Fortran

Guide To Learn

Using allocatable Arrays with Bounds

This example demonstrates using allocatable arrays with dynamic bounds.

codeprogram allocatable_arrays
    implicit none
    integer, allocatable :: array(:)
    integer :: n, i

    n = 5
    allocate(array(n))

    ! Initialize and print array
    do i = 1, n
        array(i) = i * 10
    end do

    print *, 'Array elements:'
    do i = 1, n
        print *, array(i)
    end do

    ! Deallocate array
    deallocate(array)
end program allocatable_arrays
Using allocatable Arrays with Bounds

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top