Reassigning a reference : reference « Data Type « C++






Reassigning a reference

  
#include <iostream>

int main()
{
   using namespace std;
   int  intOne;
   int &rSomeRef = intOne;

   intOne = 5;
   cout << "intOne:    " << intOne << endl;
   cout << "rSomeRef:  " << rSomeRef << endl;
   cout << "&intOne:   "  << &intOne << endl;
   cout << "&rSomeRef: " << &rSomeRef << endl;

   int intTwo = 8;
   rSomeRef = intTwo;  // not what you think!
   cout << "\nintOne:    " << intOne << endl;
   cout << "intTwo:    " << intTwo << endl;
   cout << "rSomeRef:  " << rSomeRef << endl;
   cout << "&intOne:   "  << &intOne << endl;
   cout << "&intTwo:   "  << &intTwo << endl;
   cout << "&rSomeRef: " << &rSomeRef << endl;
   return 0;
}
  
    
  








Related examples in the same category

1.constant references
2.returning a reference to a string
3.using references for int
4.Taking the Address of a Reference
5.swap() Rewritten with References
6.Passing by Reference Using Pointers
7.Passing Objects by Reference
8.Passing References to Objects
9.Returning multiple values from a function using references
10.Creating and Using References for integer
11.Data Slicing With Passing by Value
12.References for int type variable