2 ms·
That's standard behavior for object oriented languages. A different example with functions: function add(x, y) { return x + y } a = 5 add(a, 1)
by pmontra 7y ago
That's standard behavior for object oriented languages. A different example with functions:
function add(x, y) {
return x + y
}
a = 5
add(a, 1)
print(a)
A language printing 6 is pass by reference. A language printing 5 is pass by value.
Both would print 6 for this code
a = add(a, 1)
print(a)
However a language like Erlang would end with an error when trying to reassign a new value to a.
- pmontra 7y agoI correct myself. The function in the first example should be function add(x, y) { x = x + y return x }