// firstref.cpp -- defining and using a reference
#include <iostream>
int main()
{
using namespace std;
int rats = 101;
int& rodents = rats; // rodents is a reference
cout << "rats = " << rats;
cout << ", rodents = " << rodents << endl;
rodents++;
cout << "rats = " << rats;
cout << ", rodents = " << rodents << endl;
// some implementations require type casting the following
// addresses to type unsigned
cout << "rats address = " << &rats;
cout << ", rodents address = " << &rodents << endl;
// cin.get();
return 0;
}
//rats = 101, rodents = 101
//rats = 102, rodents = 102
//rats address = 0000007D94F1FCD4, rodents address = 0000007D94F1FCD4
// secref.cpp -- defining and using a reference
#include <iostream>
int main()
{
using namespace std;
int rats = 101;
int& rodents = rats; // rodents is a reference
cout << "rats = " << rats;
cout << ", rodents = " << rodents << endl;
cout << "rats address = " << &rats;
cout << ", rodents address = " << &rodents << endl;
int bunnies = 50;
rodents = bunnies; // can we change the reference?
cout << "bunnies = " << bunnies;
cout << ", rats = " << rats;
cout << ", rodents = " << rodents << endl;
cout << "bunnies address = " << &bunnies;
cout << ", rodents address = " << &rodents << endl;
// cin.get();
return 0;
}
//rats = 101, rodents = 101
//rats address = 00000057A8B5FBE4, rodents address = 00000057A8B5FBE4
//bunnies = 50, rats = 50, rodents = 50
//bunnies address = 00000057A8B5FC24, rodents address = 00000057A8B5FBE4