// Code derived from Stroustrup's PPP2 book// § 8.5.6 Pass-by-value vs. pass-by-reference// -and beginning on p 281#include<iostream>#include<vector>usingnamespacestd;voidf([[maybe_unused]]inta,int&r,constint&cr){++a;// change the local a++r;// change the object referred to by r// ++cr; // error: cr is constcout<<cr<<'\n';}voidg([[maybe_unused]]inta,int&r,constint&cr){++a;// change the local a++r;// change the object referred to by rintx=cr;// read the object referred to by crcout<<x<<'\n';}intmain(){intx=0;inty=1;intz=0;g(x,y,z);// x==0; y==1; z==0// g(1, 2, 3); // error: reference argument r needs a variable to refer tog(1,y,3);// ok: since cr is const we can pass a literal// means: int __compiler_generated = 3; g(1,y,__compiler_generated)}//---intincr1(inta){returna+1;}// return the new value as the resultvoidincr2(int&a){++a;}// modify object passed as referencevoidfoo(){intx=7;x=incr1(x);// pretty obviousincr2(x);// pretty obscure}//---// make each element in v1 the larger of the corresponding elements in v1 and v2// similarly, make each element of v2 the smallervoidlarger(vector<int>&v1,vector<int>&v2){for(inti=0;i<(int)v1.size();++i)if(v1[i]<v2[i])swap(v1[i],v2[i]);}voidf(){vector<int>vx;vector<int>vy;// read vx and vy from inputlarger(vx,vy);// ...}