C++ program to implement Call by value

To write a C++ program to implement the Call by value concept

0
589

C++ program to implement Call by value

CONSTRUCTION:

  1. Read two integers as input.
  2. Pass the numbers to the function using call by value method of passing.
  3. Perform swapping inside the function.
  4. Display the value of integers.
  5. Terminate the program.

PROGRAM:

#include<iostream.h>
void swap(int a,int b)
{
 int t;
 t=a;
 a=b;
 b=t;
}
void main()
{ 
 int x,y;
 cin>>x>>y;
 cout<<”Before Swapping:”<<x<<y;
 swap(x,y);
 cout<<”After Swapping:”<<x<<y;
}

Leave a Reply