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 ![]() ![]() |
||
![]() ![]() ![]() ![]() ![]() ![]() |
||
Declaring Pointers and References
int* x; To declare a reference, you do the exact same thing you did to declare a pointer, only this time, rather than using an asterix *, use instead an ampersand &. SOMETYPE& sometype;int& x; As you probably have already learned, spacing in C++ does not matter, so the following pointer declarations are identical: SOMETYPE* sometype;SOMETYPE * sometype; SOMETYPE *sometype; The following reference declarations are identical as well: SOMETYPE& sometype;SOMETYPE & sometype; SOMETYPE &sometype;
|
||
Home ![]() ![]() |