Pass By Value - Function

What is Function Calls?
How to pass by value in C++?


Pass by value or Call by value is the method where a copy of the value of the variables are passed to the function to do specific operation to return the result. The actual values of the variable remains unchanged as changes are made to the copied values of the variables.

Example :

#include <iostream.h>
multiply(int a, int b)
int r;
r = a * b;
return (r);
int main()
int x,y;
cout << "Enter the first integer::"; cin >> x;
cout << "Enter the second integer::"; cin >> y;
cout << "Product of X and Y is::" << multiply(x,y);

Result :

Enter the first integer::10
Enter the second integer::2
Product of X and Y is::20

In the above example the product of the numbers are calculated by passing the copy of values for "x,y" to the variables "a,b" in the function "multiply" This is the function calls in C++.

C++ Tutorial

Ask Questions

Ask Question