Does Allocating a Pointer in FORTRAN Give it a New Address?

  • Context: Fortran 
  • Thread starter Thread starter Niles
  • Start date Start date
  • Tags Tags
    Fortran
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 5K views
Niles
Messages
1,834
Reaction score
0
Hi all.

When I have the following code in FORTRAN:

Code:
integer, pointer :: ptr
ALLOCATE(ptr)

then does "ptr" receive 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 => ...")?
 
Physics news on Phys.org
That is a bit weird just allocating a single integer. If you did this:

integer, pointer :: ptr(:)
allocate(ptr(20))

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.
 
Niles said:
Hi all.

When I have the following code in FORTRAN:

Code:
integer, pointer :: ptr
ALLOCATE(ptr)

then does "ptr" receive 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 => ...")?
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.