Arguments passed by reference - C++ Function

C++ examples for Function:Function Parameter

Description

Arguments passed by reference

Demo Code

#include <iostream>
using namespace std;
int main()//from  w  w  w  .  java2s .c o  m
{
   void centimize(double&);    //prototype
   double var = 10.0;          //var has value of 10 inches
   cout << "var = " << var << " inches" << endl;
   centimize(var);             //change var to centimeters
   cout << "var = " << var << " centimeters" << endl;
   return 0;
}
void centimize(double& v)
{
   v *= 2.54;                  //v is the same as var
}

Result


Related Tutorials