<Pointer Assignment Example Program 1>

Program pointer_asgn_example_1
  Integer,Pointer :: p,q(:)
  Integer,Target :: x(10) = (/ (i,i=1,10) /)
  p => x(1)
  Print *,p
  p => x(7)
  Print *,p
  q => x(2:10:3)
  q = q + p
  Print *,q
End Program

■ Execution Results

 1
 7
 9 12 15

<Pointer Assignment Example Program 2>

Program pointer_asgn_example_2 ! Lower-bounds setting.
  Integer,Pointer :: p(:,:)
  Integer,Target :: y(-10:10,1000:2000)
  p => y
  Print 1,Lbound(p),Ubound(p)
1 Format(1X,'Lower bounds are ',I0,1X,I0,', and the upper bounds are ',I0,1X,I0)
  p(1:,0:) => y
  Print 1,Lbound(p),Ubound(p)
End Program

■ Execution Results

 Lower bounds are -10 1000, and the upper bounds are 10 2000
 Lower bounds are 1 0, and the upper bounds are 21 1000

<Pointer Assignment Example Program 3>

Program pointer_asgn_example_3 ! Rank remapping.
  Integer,Pointer :: diagonal(:),matrix(:,:),storage(:)
  Integer i,j
  Allocate(storage(9))
  matrix(1:3,1:3) => storage
  diagonal => storage(1::4)
  matrix = 0
  diagonal = 1
  Print 1,((matrix(i,j),j=1,3),i=1,3)
1 Format(1X,3I5)
End Program

■ Execution Results

     1    0    0
     0    1    0
     0    0    1