daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top