Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • Running this program should help anyone understand this concept. pastebin.com/VEc8NQcX Commented Nov 3, 2020 at 10:26
  • In this example you've not copied the Student object, so I think saying "passing a copy of the value also changes the real value of the object" is misleading. The thing that you are copying, and passing-by-value, is the reference to the object. The object stays living on the heap, and there's just one of them. That's why when you use the new reference to mutate the object, you're mutating it for everyone else that has a reference to the object. There's only one object. When the argument of the function is a primitive type, not a reference to an object, it is also copied. Commented Nov 14, 2020 at 11:57