C++ examples for Data Type:Reference
Reassignment of reference
#include <iostream> int main() // ww w . j a v a 2 s . com { int intOne; int &rSomeRef = intOne; intOne = 5; std::cout << "intOne:\t" << intOne << std::endl; std::cout << "rSomeRef:\t" << rSomeRef << std::endl; std::cout << "&intOne:\t" << &intOne << std::endl; std::cout << "&rSomeRef:\t" << &rSomeRef << std::endl; int intTwo = 8; rSomeRef = intTwo; // not what you think! std::cout << "\nintOne:\t" << intOne << std::endl; std::cout << "intTwo:\t" << intTwo << std::endl; std::cout << "rSomeRef:\t" << rSomeRef << std::endl; std::cout << "&intOne:\t" << &intOne << std::endl; std::cout << "&intTwo:\t" << &intTwo << std::endl; std::cout << "&rSomeRef:\t" << &rSomeRef << std::endl; return 0; }