#include #include using namespace std; int main() { int a = 1; int b = 3; int x; int y; cout << "value of a: " << a << endl; cout << "value of b: " << b << endl; cout << "address of a:" << &a << endl; cout << "address of b:" << &b << endl; cout << "address of x:" << &x << endl; cout << "address of y:" << &y << endl; return 0; } // int main() { // int a = 3; // int* pa; // pa = &a; // // int b = 4; // int* pb = &b; // int c = *pb; // // cout << "c is: " << c << endl; // // *pb = 101; // // cout << "*pb is: " << *pb << endl; // cout << "b is: " << b << endl; // // return 0; // } //int main() { // int a = 1; // int b = 2; // int* pa = &a; // cout << "a = " << a << " at address " << &a << endl; // cout << "b = " << b << " at address " << &b << endl; // cout << "pa = " << pa << " at address " << &pa << endl; // cout << "pa points to the value at address " << pa // << " which is " << *pa << endl; // // return 0; //} //int main() { // int a = 70; // int b = 421; // int* pA; // int* pB; // // pA = &a; // pB = pA; // // cout << "a = " << a << " at address " << &a << endl; // cout << "b = " << b << " at address " << &b << endl; // cout << "pA = " << pA << " at address " << &pA << endl; // cout << "pA points to the value at address " << pA // << " which is " << *pA << endl; // cout << "pB = " << pB << " at address " << &pB << endl; // cout << "pB points to the value at address " << pB // << " which is " << *pB << endl; // // // Do not do this: // // // &a = pA; // attempts to change the address of a // // pA = a; // attempts to change pA to an invalid address // // *pA = pB; // attempts to assign address to a signed integer // // pA = *pB; // attempts to assign pA an invalid address // // return 0; //} //int main() { // int x, y; // const int* px = &x; // value of pointer can't be changed // px = &y; // NOT OK ("change the value of px to this other address") // *px = 3; // ok ("change the value stored at the address pointed to") // // const int* r = &x; // value of variable stored at // // address pointed to can't be changed // r = &y; // ok ("change the value of px to this other address") // *r = 3; // NOT OK ("change the value stored at the address pointed to") // // const int* const q = &x; // nothing associated w/ the pointer can change // q = &y; //disallowed // *q = 3; //disallowed // // return 0; //} //int main() { // int x[4] = {100,200,300,400}; // int *px = x; // // cout << "x = " << x << " at address " << &x << endl; // cout << "px = " << px << " at address " << &px << endl; // cout << "px points to the value at address " << px // << " which is " << *px << endl; // // ++px; // cout << "px = " << px << " at address " << &px << endl; // cout << "px points to the value at address " << px // << " which is " << *px << endl; // // px = &x[2]; // cout << "px = " << px << " at address " << &px << endl; // cout << "px points to the value at address " << px // << " which is " << *px << endl; // // return 0; //}