#include using namespace std; // prototype for pass-by-value int negX(int i); // prototype for reference void negXbyRef(int &y); // prototype for pointer void negX(int *y); // negation of x int main() { int x = 0; // I/O cout << endl << "Please enter an integer: "; cin >> x; // calculation w/o function cout << "Original x: " << x << endl; x = -x; cout << "New x: " << x << endl; /* * * PASS BY VALUE * * */ cout << endl << "*** PASS BY VALUE ***" << endl; cout << "Before the function x = " << x << endl; x = negX(x); cout << "Negative x (or what is now x's value): " << x << endl; /* * * PASS BY REFERENCE * * */ cout << endl << "*** PASS BY REFERENCE ***" << endl; cout << "Before pass by reference x = " << x << endl; negXbyRef(x); cout << "Negative x (or what is now x's value): " << x << endl; /* * * POINTERS (ADDRESSES) * * */ cout << endl << "*** POINTERS ***" << endl; cout << "Original x = " << x << endl; negX(&x); cout << "Negative x (or what is now x's value): " << x << endl; return 0; } // pass-by-value int negX(int k) { return -k; } // using references void negXbyRef(int &z) { z *= -1; } // using pointers void negX(int *z) { *z *= -1; }