-
Notifications
You must be signed in to change notification settings - Fork 0
/
psap.cpp
49 lines (45 loc) · 962 Bytes
/
psap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//Exploring different methods of passing parameters to functions by Vishruth Codes
#include<iostream>
using namespace std;
int passbyvalue(int l, int r)
{
return l*r;
}
int passbyaddress(int *l,int *r)
{
return (*l)*(*r);
}
int passbyreference(int &l, int &b)
{
return l*b;
}
int main()
{
int n, are,l,b;
cout<<"\nEnter the length: ";
cin>>l;
cout<<"\nEnter the breadth: ";
cin>>b;
cout<<"\nHow do you wanna calculate the area (the results are same for all): ";
cout<<"\n\n1. pass by value\n2. pass by address\n3. pass by reference\n:- ";
cin>>n;
switch(n)
{
case 1:{
are = passbyvalue(l,b);
cout<<"\nThe area is: "<<are;
break;
}
case 2:{
are = passbyaddress(&l,&b);
cout<<"\nThe area is: "<<are;
break;
}
case 3:{
are = passbyreference(l,b);
cout<<"\nThe area is: "<<are;
break;
}
}
return 0;
}