As c is no primitive, d = c sets the value of d to the same reference pointer that references c.
That means c.greeting = ... means "lookup the object referenced by c and mutate its value".
As c and d are only references to the same object, the Output is, of course, 'Hello'.
Everyone confused by this behavior should start looking into the basics of a functional programming style ;)
Top comments (6)
As
cis no primitive,d = csets the value ofdto the same reference pointer that referencesc.That means
c.greeting = ...means "lookup the object referenced by c and mutate its value".As
canddare only references to the same object, the Output is, of course,'Hello'.Everyone confused by this behavior should start looking into the basics of a functional programming style ;)
A: Hello
correct
A. Hello
correct answer
So this would be a example of "Pass by reference"?