Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void call_by_value(int a)
- {
- cout<<__func__<<": a="<<a<<endl;
- a = 20;
- }
- void call_by_address(int *a)
- {
- cout<<__func__<<": a="<<*a<<endl;
- *a = 30;
- }
- void call_by_reference(int& a)
- {
- cout<<__func__<<": a="<<a<<endl;
- a = 40;
- }
- int main()
- {
- int n = 10;
- call_by_value(n);
- cout<<"after call_by_value: n="<<n<<endl;
- call_by_address(&n);
- cout<<"after call_by_address: n="<<n<<endl;
- call_by_reference(n);
- cout<<"after call_by_reference: n="<<n<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment