Create double type reference as alias for a variable - C++ Data Type

C++ examples for Data Type:Reference

Description

Create double type reference as alias for a variable

Demo Code

#include <iostream>
using namespace std;
int main()//from   w ww  .  j a va 2s  .  c o  m
{
   double total = 20.5;  // declare and initialize total
   double& sum = total;  // declare another name for total
   cout << "sum = " << sum << endl;
   sum = 18.6;           // this changes the value in total
   cout << "total = " << total << endl;
   return 0;
}

Result


Related Tutorials