Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

FORTRAN: Allocating a pointer

  1. Oct 18, 2009 #1
    Hi all.

    When I have the following code in FORTRAN:

    Code (Text):

    integer, pointer :: ptr
    then does "ptr" recieve a new address (i.e. do we have "ptr => <new integer>") or does the pointer retain its address (i.e. we don't have "ptr => ...")?
  2. jcsd
  3. Oct 23, 2009 #2
    That is a bit weird just allocating a single integer. If you did this:

    integer, pointer :: ptr(:)

    Then an array of 20 integers would be allocated and ptr would be set to point to the new array. If ptr already points to an array then that array will not automatically be deallocated.
  4. Oct 24, 2009 #3


    User Avatar
    Science Advisor

    What do you mean a "new" address? When you declare the pointer, there is NO memory location assigned to it until memory is allocated to it.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook