Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- C++
- */
- #include <iostream>
- using namespace std;
- void changeInt(int *v, int newVal){
- /*
- Change int with a function, using pointers.
- */
- *v = newVal;
- }
- int main() {
- /*
- First:
- int x, declared with 0 value
- pointer to x
- we see the x value
- we change the x value to 10
- we see the new x value
- */
- int x = 0;
- int *p = &x;
- cout << x << endl;
- changeInt(p, 10);
- cout << x << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment