Write a program of pass by value


 

/* Write a program of pass by value*/

#include<iostream.h>

#include<conio.h>

#include<iomanip.h>

void main()

{

int a,b;

clrscr();

void swap(int,int);

cout<<“enter two numbers=”;

cin>>a>>b;

cout<<“\n before calling a=”<<a<<“b=”<<b;

swap(a,b);

cout<<“\n after calling a=”<<a<<“b=”<<b;

getch();

}

void swap(int x,int y)

{

int z;

z=x;

x=y;

y=z;

 cout<<“\n after modification of x=”<<x<<“y=”<<y;

}

output:

enter two numbers=10 25

before calling a=10 b=25

after modification x=25 y=10

after calling a=10 b=25

 

Related Posts

Comments are closed.