C++ Program For Call by Value and Return by Value
Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
// Function declaration and definition
#include<iostream>
#define clrscr() system("cls")
using namespace std;
int add(int a,int b);
int main()
{
clrscr();
int a,b,c;
cout<<"Enter two number";
cin>>a>>b;
c=add(a,b); //call by value
cout<<"Additon is : "<<c;
return 0;
}
int add(int a,int b)
{
int c;
c=a+b;
return c;
}Program 2
// Function declaration and definition
#include<iostream>
#define clrscr() system("cls")
using namespace std;
int reverse(int n);
int main()
{
int n,x;
clrscr();
cout<<"\nEnter a number";
cin>>n;
cout<<"\nIn Main value of n before calling: "<<n;
x=reverse(n);
cout<<"\nIn Main value of n after calling: "<<n;
cout<<"\nReverse is : "<<x;
if(x==n)
cout<<"\n No is palindrom";
else
cout<<"\n No is not palindrom";
}
int reverse(int n)
{
int r,s=0;
cout<<"\nIn Function before loop value of n: "<<n;
while(n!=0)
{
r=n%10;
s=(s*10)+r;
n=n/10;
}
cout<<"\nIn Function after loop value of n: "<<n;
return (s);
}
Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

