Guest User

Untitled

a guest
Oct 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void call_by_value(int a)
  6. {
  7. cout<<__func__<<": a="<<a<<endl;
  8. a = 20;
  9. }
  10.  
  11. void call_by_address(int *a)
  12. {
  13. cout<<__func__<<": a="<<*a<<endl;
  14. *a = 30;
  15. }
  16.  
  17. void call_by_reference(int& a)
  18. {
  19. cout<<__func__<<": a="<<a<<endl;
  20. a = 40;
  21. }
  22.  
  23. int main()
  24. {
  25. int n = 10;
  26. call_by_value(n);
  27. cout<<"after call_by_value: n="<<n<<endl;
  28. call_by_address(&n);
  29. cout<<"after call_by_address: n="<<n<<endl;
  30. call_by_reference(n);
  31. cout<<"after call_by_reference: n="<<n<<endl;
  32.  
  33. return 0;
  34. }
Add Comment
Please, Sign In to add comment