Jump to content

Array concatenation: Difference between revisions

m
mNo edit summary
Line 1,055:
implicit none
 
integer, dimension(3) :: a = [ (/1, 2, 3 ]/)
integer, dimension(3) :: b = [ (/4, 5, 6 ]/)
integer, dimension(:), allocatable :: c, d
allocate(c(size(a)+size(b)))
c(1 : size(a)) = a
c(size(a)+1 : size(a)+size(b)) = b
 
write(*,*) c
 
! alternative
cd = [(/a, b]/)
write(*,*) d
 
deallocate(c)
deallocate(d)
 
end program Concat_Arrays</lang>
Line 1,071 ⟶ 1,077:
implicit none
 
integer, dimension(3) :: a = [ 1, 2, 3 ]
integer, dimension(3) :: b = [ 4, 5, 6 ]
integer, dimension(:), allocatable :: c, d
allocate(c(size(a)+size(b)))
c = [a, b]
c[1 : size(a)] = a
 
c[size(a)+1 : size(a)+size(b)] = b
write(*,*) c
 
! alternative
d = [a, b]
write(*,*) d
 
deallocate(c)
deallocate(d)
 
end program Concat_Arrays</lang>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.