// refs.cpp #include #include using namespace std; int main() { int A = 1; // declare and define A int B = 2; // declare and define next memory location after A int *p = &A; // p points to A int &refA = A; // alias (reference) for A *p = 3; // *p points to A, so A is assigned 3 cout << "initially: "; cout << " A=" << A << " p=" << p << " *p=" << *p << " refA=" << refA; cout << " &A=" << &A << " &p=" << &p << " &refA=" << &refA; cout << endl; A = *p + 1; // A is assigned value of *p=7 plus 1 cout << "after A=*p+1: "; cout << " A=" << A << " p=" << p << " *p=" << *p << " refA=" << refA; cout << " &A=" << &A << " &p=" << &p << " &refA=" << &refA; cout << endl; A = refA + 1; // A is assigned value of refA=7 plus 1 cout << "after A=refA+1: "; cout << " A=" << A << " p=" << p << " *p=" << *p << " refA=" << refA; cout << " &A=" << &A << " &p=" << &p << " &refA=" << &refA; cout << endl; A++; cout << "after A++ "; cout << " A=" << A << " p=" << p << " *p=" << *p << " refA=" << refA; cout << " &A=" << &A << " &p=" << &p << " &refA=" << &refA; cout << endl; p++; cout << "after p++ "; cout << " A=" << A << " p=" << p << " *p=" << *p << " refA=" << refA; cout << " &A=" << &A << " &p=" << &p << " &refA=" << &refA; cout << endl; refA++; cout << "after refA++ "; cout << " A=" << A << " p=" << p << " *p=" << *p << " refA=" << refA; cout << " &A=" << &A << " &p=" << &p << " &refA=" << &refA; cout << endl; }