Talk:Language Comparison Table: Difference between revisions

C++ definitely has passing by reference
(C/C++ uses only by-value passing mode!)
(C++ definitely has passing by reference)
Line 13:
 
[[C]] and [[C++]] have only by-value passing mode. See an explanation in [[Parameter Passing]] --[[User:Dmitry-kazakov|Dmitry-kazakov]] 17:03, 25 July 2008 (UTC)
 
: That's not true for C++: In C++, pass by reference is possible by just using a reference for the argument, f.ex.
<cpp>
void foo(int& i)
{
i = 0
}
 
int main()
{
int rc = 1;
foo(rc); // sets rc to 0
return rc;
}
</cpp>
: Note that the explanation for C++ references in [[Parameter Passing]] is not correct: Objects are not ''converted'' to references, they are ''bound'' to references. Reference types in C++ are fundamentally different to all other types, as they do ''not'' denote objects, but, well, references to objects. The references themselves are not objects (you cannot have a pointer or reference to them, you cannot assign them — using them on the left hand of an assignment assigns to the object they refer to —, you cannot determine their size, etc.). Logically they just give a name to an existing object (the compiler may store the address to the object named by the reference, but that's an implementation detail). --[[User:Ce|Ce]] 13:15, 5 August 2008 (UTC)
973

edits