2 ms·
Popular as it is, C++ is still a pretty special case. Not many languages have references like it. (I personally don’t use any.) int a = 5; int& b = a; b
by minitech 8y ago
Popular as it is, C++ is still a pretty special case. Not many languages have references like it. (I personally don’t use any.)
int a = 5;
int& b = a;
b = 6;
// a is now 6
Allowing an lvalue argument to be changed by a function call is something more languages support, though, like C# and VB.NET. That’s what it means to “pass by reference”. Passing a reference/pointer is an accurate description of how most languages work, which might sound similar, but is really different enough to warrant not being called that. Especially because the behaviour has nothing to do with passing: variables just work that way in general in Python, Java, JavaScript, Ruby, C#, VB.NET, Lua, ….
Anyway, back to:
> I may be missing something, but I can't find any example in my mind which indicates difference between passing in Java and Python.
You’re right that C extensions can break the rules, but in the real world they don’t (because that breaks everything); immutable int objects are effectively primitives. (Modern JavaScript – in strict mode – is an example of a language that hides the implementation details of primitives better than Java.)