// Code derived from Stroustrup's PPP2 book// § 8.5.5 Pass-by-reference// -and beginning on p 279#include<cmath>#include<iostream>#include<vector>usingnamespacestd;intg(int&x);intf(int&x);voidh(intx,inty){inti=7;int&r=i;// r is a reference to ir=9;// i becomes 9i=10;// r becomes 10cout<<r<<' '<<i<<'\n';// print: 10 10vector<vector<double>>v;// vector of vector of double (a 2D container)doubleval=v[f(x)][g(y)];// val is the value of v[f(x)][g(y)]double&var=v[f(x)][g(y)];// var is a reference to v[f(x)][g(y)]var=var/2+sqrt(var);cout<<val<<'\n';}// pass-by-reference (let the function refer back to the variable passed)intf(int&x){x=x+1;returnx;}intmain(){intxx=0;cout<<f(xx)<<endl;// print: 1cout<<xx<<endl;// print: 1; f() changes the value of xxintyy=7;cout<<f(yy)<<endl;// print: 8cout<<yy<<endl;// print: 8; f() changes the value of yy}intg(int&x){x=x+1;returnx;}