Using the Address of Operator on References

If you ask a reference for its address, it returns the address of its target. That is the nature of references—they are aliases for the target. Listing 11.2 demonstrates this.

Listing 11.2. Taking the Address of a Reference
 1:  // Demonstrating the use of References
 2:  #include <iostream>
 3:
 4:  int main()
 5:  {
 6:      int  intOne;
 7:      int &rSomeRef = intOne;
 8:
 9:      intOne = 5;
10:      std::cout << "intOne: " << intOne << std::endl;
11:      std::cout << "rSomeRef: " << rSomeRef << std::endl;
12:
13:      std::cout << "&intOne: "  << &intOne << std::endl;
14:      std::cout << "&rSomeRef: " << &rSomeRef << std::endl;
15:
16:      return 0;
17:  }
intOne: 5
rSomeRef: 5
&intOne: 0x0012FF7C
&rSomeRef: 0x0012FF7C
					

Once again, rSomeRef ...

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.