3 ms·
Go is only pass by value. Much in the same way JavaScript is (the best description for JS, IMO, is reference by value). Even if you pass a pointer, the pointer
by andrewstuart2 8y ago
Go is only pass by value. Much in the same way JavaScript is (the best description for JS, IMO, is reference by value).
Even if you pass a pointer, the pointer is explicitly copied to a new location in memory, which is why assignment to the pointer can overwrite the pointer, but not affect the original pointer (the memory location value inside the pointer-typed variable) outside the function scope.
Pass by reference is when assignment to a parameter name is transitive to the caller's scope, and can be seen in C#. [1]
[1] https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ref https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
- int_19h 8y agoNow that C# has ref locals, it's not really pass-by-reference so much so as C++-style (or Algol-68 style, if you go far enough) references that are implicitly dereferenced on access and cannot be rebound.