Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void addThree(int *x) *dereferences address
- {
- *x = *x + 3;
- }
- int main()
- {
- int x = 5;
- addThree(&x); //send memory address of x to addThree()
- printf("%d\n", x);
- return 0;
- }
- in C++ you could do this:
- void addThree(int &x)
- {
- x = x + 3;
- }
- int main()
- {
- int x = 5;
- addThree(x);
- printf("%d\n", x);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement