SHARE
TWEET

Untitled

a guest Oct 9th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. void by_reference(int &number) {
  8.     cout << "reference in by_reference " << &number << endl;
  9.     cout << "by reference" << endl;
  10.     cout << number << endl;
  11.     number=100;
  12.     cout << number << endl;
  13.     cout << "-------------" << endl;
  14. }
  15.  
  16. void by_value(int number) {
  17.     cout << "reference in by_value " << &number << endl;
  18.     cout << "value in by_value " << *(&number) << endl;
  19.     cout << "by value" << endl;
  20.     cout << number << endl;
  21.     number++;
  22.     cout << number << endl;
  23.     cout << "-------------" << endl;
  24. }
  25.  
  26. int main()
  27. {
  28.   int number = 1;
  29.   cout << "reference in main " << &number << endl;
  30.   cout << "value in main " << *(&number) << endl;
  31.   by_value(1);
  32.   //cout << number << endl;
  33.   by_reference(number);
  34.   cout << "value in main after changing " << *(&number) << endl;
  35.   return 0;
  36. }
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