swap(a, b);
You have to write swap(&a, &b); swap(a, b);
You have to write swap(&a, &b);That's why people call "pass-by-reference" the second example.
The C example is equivalent to
pa = &a;
pb = &b;
swap(pa, pb);
When swap returns, the values of pa and pb are unchanged. Only the values or a and b are changed. But a and b were not passed to swap. Therefore this is not pass-by-reference, but rather passing a pointer to a variable by value.What I'm saying is that people tend to abbreviate "pass-a-reference-by-value" to "pass-by-reference" because the differences between passing a value (value snapshot) and passing a reference-value (passing the address-of) are way more important* than if the language syntax allows you to pass an "implicit" variable reference or not. (the swap example)
*"more important" for code-reading, code-analysis, code-safety analysis, and also even more important in a concurrent environment because of side-effects and data-races.
Maybe the feature should be called "pass an implicit reference", which describes better what Java does, instead of saying "everything is pass-by-value" which is correct but, as the evidence shows (the mere existence of the article), it is very confusing for "folks".
>I'm really tired of hearing folks (incorrectly) state "primitives are passed by value, objects are passed by reference".