O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required