Mix pass by value parameter and pass by as reference parameter - C++ Function

C++ examples for Function:Function Parameter

Description

Mix pass by value parameter and pass by as reference parameter

Demo Code

#include <iostream>
using namespace std;
void calc(double, double, double, double&, double&);  // prototype
int main()//from  w ww .ja  v a 2  s.  co m
{
   double firstnum, secnum, thirdnum, sum, product;
   cout << "Enter three numbers: ";
   cin  >> firstnum >> secnum >> thirdnum;
   calc(firstnum, secnum, thirdnum, sum, product);  // function call
   cout << "\nThe sum of the numbers is: " << sum << endl;
   cout << "The product of the numbers is: " << product << endl;
   return 0;
}
void calc(double num1, double num2, double num3, double& total, double& product)
{
   total = num1 + num2 + num3;
   product = num1 * num2 * num3;
   return;
}

Result


Related Tutorials