firstref.cpp 575 B

123456789101112131415161718192021
  1. // firstref.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. rodents++;
  11. cout << "rats = " << rats;
  12. cout << ", rodents = " << rodents << endl;
  13. // some implementations require type casting the following
  14. // addresses to type unsigned
  15. cout << "rats address = " << &rats;
  16. cout << ", rodents address = " << &rodents << endl;
  17. // cin.get();
  18. return 0;
  19. }