/////////////////////////////////////////////////////////////// // basic0.cpp - declare, create and use references // // and compare with pointers // ver 1 // // Jim Fawcett, CSE687, S00 // /////////////////////////////////////////////////////////////// #include // cout #include // C style strings // // Note: // & to the left of an "=" is a reference // & to the right of an "=" is an address // Otherwise: // & in a declaration is a reference // & in an expression is an address // void main() { std::cout << "\n Demonstrate pointers and references " << "\n =====================================\n"; // declare object, pointer to it, and use int x = 2; int *pInt = &x; std::cout << "\n contents of location pointed to by pInt = " << (*pInt); *pInt = 3; std::cout << "\n modified contents of location pointed to by pInt = " << (*pInt) << std::endl; // declare reference and use it int &rInt = x; std::cout << "\n contents of location referred to by rInt = " << rInt; rInt = 2; std::cout << "\n modified contents of location referred to by rInt = " << rInt << std::endl; std::cout << "\n\n"; }