Advertisement
Guest User

Untitled

a guest
Feb 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void addThree(int *x) *dereferences address
  4. {
  5.     *x = *x + 3;
  6. }
  7.  
  8. int main()
  9. {
  10.     int x = 5;
  11.     addThree(&x); //send memory address of x to addThree()
  12.     printf("%d\n", x);
  13.    
  14.     return 0;
  15. }
  16.  
  17. in C++ you could do this:
  18.  
  19. void addThree(int &x)
  20. {
  21.     x = x + 3;
  22. }
  23.  
  24. int main()
  25. {
  26.     int x = 5;
  27.     addThree(x);
  28.     printf("%d\n", x);
  29.    
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement