What is actually passed in the call through a function reference?
void foo(int &a,int &b)
when I write
foo(p,q)
what is actually passed to the function. Is this the address of p and q?
What is actually passed to the function is a link. The named parameter bbecomes a synonym for the argument object q.
b
q
, , , q , b. , " " , ++, , . , , , , (). , .
, , , " ", , . , char 4- , , " int". , " ".
char
.
, - , - . , .
SO: ?
- , . . , , , , . Wikipedia .
, , , .
"" , . - . .
:
int foo(int& a, int& b) { a = b; } // Usage int x, y; foo(x, y);
, :
int foo(int* a, int* b) { *a = *b; } // Usage int x, y; foo(&x, &y);
, ( ).
, , , . :
void foo(int& x) { std::cout << &x << std::endl; } int y; std::cout << &y << std::endl; foo(); // This will print the same as above.
. int&, ++. :
int&
int x = 10; int& y = x; x = 100;
, y? , . , int&, .
void byRef(int& x) { return; } void byVal(int x) { return; } void byPtr(int * x) { return; } int _tmain(int argc, _TCHAR* argv[]) { int x = 0; byRef(x); byVal(x); byPtr(&x); return 0; }
MSVC90, byRef byPtr, :
byRef
byPtr
lea eax, [x] push eax call byRef ;or byPtr add esp, 4
Source: https://habr.com/ru/post/1735988/More articles:Recursively a ZIP directory containing any number of files and subdirectories in Java? - javaChoosing Options in Diffie-Hellman - cParsec: backtracking not working - haskellGetting a value from a field in a DataTable when the column name has spaces - c #Internet Explorer shows an error message when I try to open a local html file with parameters - urlGreat view of datasets in C / C ++ - c ++Dynamically setting the maximum heap size for a Java process - javahelp translate this query for a week from Oracle PL / SQL to SQL Server 2008 - sqlSession management and linking user accounts with OpenID, in ASP.NET - c #WinForm - WPF integration; Piece by piece - .netAll Articles