August 2001
Beginner
482 pages
10h 52m
English
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.
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 ... |
Read now
Unlock full access