Clicky

Fortran Wiki
pointer_example (changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #1 to #2: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

An example of pointer usage in Fortran:

program pointer_example
 real, target :: a, b, c
 real, pointer :: p, q
 ! Define some values
 a = 3.1416
 b = 2.7182
 c = 0.5772
 ! The following pointer associations result in
  ! a = p = 3.1416 and b = q =(削除) 3.1416 (削除ここまで)(追記) 2.7182 (追記ここまで)
 p => a
 q => b
 call print_values()
 ! If we use conventional assignment, all four variables
 ! a, b, p, and q will be 3.1416
 q = p
 call print_values()
 ! Alternatively, if we can use pointer association
 ! to set p = c = 0.5772 without changing a, b, or q.
 p => c
 call print_values()
contains
 subroutine print_values()
 print *, 'Values:'
 print *, 'a = ', a
 print *, 'b = ', b
 print *, 'c = ', c
 print *, 'p = ', p
 print *, 'q = ', q
 end subroutine print_values
end program pointer_example

The output of this program is:

 Values:
 a = 3.141600 
 b = 2.718200 
 c = 0.5772000 
 p = 3.141600 
 q = 2.718200 
 Values:
 a = 3.141600 
 b = 3.141600 
 c = 0.5772000 
 p = 3.141600 
 q = 3.141600 
 Values:
 a = 3.141600 
 b = 3.141600 
 c = 0.5772000 
 p = 0.5772000 
 q = 3.141600 

category: code

Revised on March 17, 2010 17:25:12 by Anonymous Coward (129.105.69.126) (1289 characters / 0.0 pages)
Edit | Back in time (1 revision) | Hide changes | History | Views: Print | TeX | Source | Linked from: Code, 2009, Pointers

AltStyle によって変換されたページ (->オリジナル) /