//reference and pointers #include #include using namespace std; int main() { int y, z; int* x, p; //pointer to integer //I set y y = 1; x = &y; //x contains the address of y (& = reference operator) //p = x; //it raises an error! z = *x; //z contains the value pointed (referenced) by x, which is equal to y cout << "y: " << y << endl; cout << "z (equal to y): " << z << endl; cout << "x (address of y): " << x << endl; //hexadecimal memory address //now, I change y y = 2; cout << "now y is: " << *x << endl; //*x contains the updated value of y cout << "z: " << z << " (y not updated!)" << endl; //z contains the old value of y cout << "now x is: "<< x << " (the address of y does not change!)" << endl; return 0; }