1
0

secref.cpp 695 B

12345678910111213141516171819202122232425
  1. // secref.cpp -- defining and using a reference
  2. #include <iostream>
  3. int main()
  4. {
  5. using namespace std;
  6. int rats = 101;
  7. int & rodents = rats; // rodents is a reference
  8. cout << "rats = " << rats;
  9. cout << ", rodents = " << rodents << endl;
  10. cout << "rats address = " << &rats;
  11. cout << ", rodents address = " << &rodents << endl;
  12. int bunnies = 50;
  13. rodents = bunnies; // can we change the reference?
  14. cout << "bunnies = " << bunnies;
  15. cout << ", rats = " << rats;
  16. cout << ", rodents = " << rodents << endl;
  17. cout << "bunnies address = " << &bunnies;
  18. cout << ", rodents address = " << &rodents << endl;
  19. // cin.get();
  20. return 0;
  21. }