The C++Course provides a general introduction to programming in C++. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |
![]() |
Home ![]() ![]() |
||
See also: Operators | ||
![]() ![]() ![]() ![]() ![]() ![]() |
||
The "Address Of" Operator
Now, do not confuse the "address of" operator with the declaration of a reference. Because use of operators is restricted to rvalues, or to the right hand side of the equation, the compiler knows that &SOMETYPE is the "address of" operator being used to denote the return of the address of SOMETYPE as a pointer. Furthermore, if you have a function which has a pointer as an argument, you may use the "address of" operator on a variable to which you have not already set a pointer to point. By doing this, you do not necessarily have to declare a pointer just so that it is used as an argument in a function, the "address of" operator returns a pointer and thus can be used in that case too. SOMETYPE MyFunc(SOMETYPE *x){ cout << *x << endl; } int main() { SOMETYPE i; MyFunc(&i); return 0; }
|
||
Home ![]() ![]() |