Returning reference values - C++ Function

C++ examples for Function:Function Return

Description

Returning reference values

Demo Code

#include <iostream>
using namespace std;
int x;                   // global variable
int& setx();             // function declaration
int main()/*from w w w  .ja va 2  s  .  c o m*/
{                     // set x to a value, using
    setx() = 92;          // function call on left side
    cout << "x=" << x << endl;  // display new value in x
    return 0;
}
int& setx()
{
    return x;             // returns the value to be modified
}

Result


Related Tutorials