CPP Program to Implementation of Call by Value

AIM:

To write a C++ program to find the value of a number raised to its power that demonstrates a function using call by value.

Description:

  • The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function.
  • In this case, changes made to the parameter inside the function have no effect on the argument.

Algorithm:

  1. Start the program.
  2. Declare the variables.
  3. Get two numbers as input
  4. Call the function power to which a copy of the two variables is passed.
  5. Inside the function, calculate the value of x raised to power y and store it in p.
  6. Return the value of p to the main function.
  7. Display the result.
  8. Stop the program.

PROGRAM:

#include<iostream>
using namespace std;
int areaofrect(int l,int b)
{
return l*b;	
} 
int main()
{
int l,b;
cin>>l>>b;
cout<<"area of rectanle :"<<areaofrect(l,b);
return 0;
}

EXECUTION:

Input:

7 9

Output:

area of rectangle :63

Result:

Thus, Implementation of Call by Value was executed successfully.

Leave a Comment