fork download
  1. ///call by value : call by reference///
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. void swp(int *x,int *y);
  5. int area(int l,int b);
  6. /*void fun1(int a) //Function Definition//Formal Argument
  7. {
  8.  
  9. }
  10. void fun2(int *p) //Function Definition//Formal Argument
  11. {
  12.  
  13. }*/
  14. int main()
  15. {
  16. //int x=5;
  17. //fun1(x); //Function Call//Actual Argument//Call by Value
  18. //fun2(&x);//Function Call//Actual Argument//Call by Reference(address)
  19. int l=5,h=10;
  20. cout<<"using call by value the area =";
  21. cout<<area(l,h)<<endl; ///CALL BY VALUE
  22. int a=2,b=3;
  23. cout<<"using call by reference after swap=";
  24. swp(&a,&b); ///Call by Reference
  25. cout<<a<<" "<<b<<endl;
  26. }
  27. int area(int l,int b)
  28. {
  29. return(l*b);
  30. }
  31. void swp(int *x,int *y)
  32. {
  33. int t,ans;
  34. t=*x;
  35. *x=*y;
  36. *y=t;
  37. }
  38.  
Success #stdin #stdout 0s 4368KB
stdin
Standard input is empty
stdout
using call by value the area      =50
using call by reference after swap=3 2