Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void AddOne(int &input) //passed by reference
- {
- input++;
- }
- int main3()
- {
- int x = 5;
- cout << "x = " << x << endl;
- AddOne(x);
- cout << "x = " << x << endl; //value of x is incremented to 6
- return 0;
- }
- //void chg(int *pValue)
- //{
- // *pValue = 6; //dereferenced pointer
- //}
- //int main()
- //{
- // int nValue = 5;
- // cout << "nValue = " << nValue << endl;
- // chg(&nValue); //pointer takes in address of nValue
- // cout << "nValue = " << nValue << endl; //nValue is changed to 6
- // return 0;
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement