From: Xavier Noria Date: 2008-08-28T20:27:29+09:00 Subject: Re: how to avoid passing by reference and how to copy objects On Thu, Aug 28, 2008 at 1:03 PM, David A. Black wrote: > C is actually a poor point of reference (ha ha) for understanding Ruby > variables and references, because the two are so different. I'd > encourage you not to worry about how Ruby semantics align with C > semantics Nevertheless C is only pass by value. That could help. There's no way in C to accomplish this a = 7; some_function(a); // a is 7 for certain here You can pass the address of a: a = 7; p = &a; some_other_function(p); // a may be 5 now but note that the argument of the function is p, it is not a. So you are clearly just passing p by value. Again, when some_other_function returns there's no way p is pointing to anything that is not a, because of pass by value semantics. In some vague sense this second example has some resemblances to Ruby: you are always passing ps in Ruby so to speak (that's an analogy, it is clear from the rest of the thread there are no actual pointers involved). Through those ps, if the object is mutable you may change the state of the object, but cannot change the very reference, the object pointed at by p, the same way you cannot in C. Java is pass by value as well.