Change the values stored in reference variables from within the called function. - C++ Function

C++ examples for Function:Function Parameter

Description

Change the values stored in reference variables from within the called function.

Demo Code

#include <iostream>
using namespace std;
void newval(double&, double&);  // prototype with two reference parameters
int main()/*w ww .jav a 2 s.  co m*/
{
   double firstnum, secnum;
   cout << "Enter two numbers: ";
   cin  >> firstnum >> secnum;
   cout << "\nThe value in firstnum is: " << firstnum << endl;
   cout << "The value in secnum is: " << secnum << "\n\n";
   newval(firstnum, secnum);   // call the function
   cout << "The value in firstnum is now: " << firstnum << endl;
   cout << "The value in secnum is now: " << secnum << endl;
   return 0;
}
void newval(double& xnum, double& ynum)
{
   cout << "The value in xnum is: " << xnum << endl;
   cout << "The value in ynum is: " << ynum << "\n\n";
   xnum = 89.5;
   ynum = 99.5;
   return;
}

Result


Related Tutorials