Cp Lab 10 Recursion
Cp Lab 10 Recursion
Lab Journal: 10
Date: 24-11-2024
Documentation
Task Wise Marks Total
Task Marks Marks
No:
Assigned Obtained Assigned Obtained (20)
1 3
2 3
3 3 5
4 3
5 3
Comments:
Signature
Hayat Nabi Computer Programming Engr. M Amin Khan
09-131242-097 Lab # 10 Dept of SE, BUIC
Lab Task :
Swapping Two Numbers: Call by Value vs Call by Reference Implement two separate
functions to swap two numbers: one using call by value and the other using call by reference.
The program should ask the user for two numbers, perform the swaps, and display the results
to demonstrate the difference between the two methods.
void PassByValue(int a , int b){ // Through this Function swap will not work
int temp = a;
a = b;
b = temp;
int main(){
int Num1,Num2;
cin>>Num1;
cin>>Num2;
cout<<"Before Pass By Value Function :\nNum1 : "<<Num1 << "\nNum2 : "<<Num2 <<endl;
PassByValue(Num1 , Num2);
Screenshot:
2
Hayat Nabi Computer Programming Engr. M Amin Khan
09-131242-097 Lab # 10 Dept of SE, BUIC
void PassByReference(int &x , int &y){ // It will swap because it reach upto memory address where it
change value
x=y;
y = temp ;
int main(){
int Num1,Num2;
cin>>Num1;
cin>>Num2;
cout<<"Before Pass By Reference Function :\nNum1 : "<<Num1 << "\nNum2 : "<<Num2 <<endl;
PassByReference(Num1 , Num2);
Screenshot: