Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:48:32+00:00 2026-06-09T11:48:32+00:00

I need a deep copy of a (real) array in Fortran (90), but am

  • 0

I need a deep copy of a (real) array in Fortran (90), but am not sure exactly how to get one, since I do not completely understand how references work. Intuitively, I would expect this to get me what I want:

do i=1,n
  b(i) = a(i)
end do

However, it was recently pointed out to me that b(1:n) = a(1:n) is equivalent to the code above. Intuitively, I would expect that b(1:n) = a(1:n) merely causes the reference of b(1:n) to point to the location of a(1:n) in memory.

Is b(1:n) = a(1:n) a deep copy? Why? What is going on with the underlying references as opposed to b = a?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:48:33+00:00Added an answer on June 9, 2026 at 11:48 am

    The three ways you mention for copying arrays, the do loop, b(1:n) = a(1:n) and b = a, are all equivalent; they copy the contents of the array a into the array b. a and b are simply arrays, not fancy pointers or anything and so the assignment a = b is basically the same as the mathematical expression. There is no magic with references going on (that the user needs to know about), which is why Fortran is a pretty straight forward language to learn. You can have pointer arrays in Fortran, but this is a whole other issue.

    M Metcalf and J Reid’s Fortran 90/95 explained is always a good reference for consulting on Fortran language features. From page 48:

    3.11 Array assignment

    By intrinsic assignment, an array expression may be assigned to an array variable of the same shape, which is interpreted as if each element of the expression were assigned to the corresponding element of the variable. For example, with the declarations

    real, dimension(10, 20) :: a
    

    The assignment

    a = a  + 1.0
    

    replaces a(i,j) by a(i,j) + 1.0 for i=1,2..,10 and j=1,2,..,20.

    Also note that a scalar expression may be assigned to an array, in which case the saclar value is broadcast to all the array elements.

    In terms of how this is all actually implemented, which is what I think you are driving at with your question, this is completely unspecified by the Fortran standard. This sort of thing is left unspecified to allow compiler writers to do whatever optimisations they feel like. For example, in the assignment a = b, the order in which the elements of b are copied into a is unspecified by the standard, so different compilers could do this in different ways. All that you need to know is that for this question is that, provided a and b are not pointers, then a and b are distinct arrays and that changing an element of one does not change the corresponding element of the other. So it a sense, a=b is a "deep copy" and you can think of this as copying all items in b to the memory location of a.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to copy an object that has a pretty deep hierarchy of member
I need to deep copy a custom object that has objects of its own.
My need: I want to deep copy all the childs of a single selected
I have a std::vector<A*> which I need to deep copy to another vector using
I made this constructor, and I need to make a deep copy of it.
I need to do a deep copy in Silverlight, which I can do with
Have a class Hero. Sometimes I need a deep copy (when all members are
I need to make a deep copy of an object. The only way I
I currently have a three dimensional NSMutableArray which I need to deep copy. However,
Does app engine's memcache.get() return a reference or deep copy? The reason I ask

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.