programminga general overview to see the reasons why call-by-value is not sufficient as the only parameter-passing mechanism in ++consider the three function declarations belowdouble averagedouble adouble )/returns average of and void swapdouble adouble )/swaps and bwrong parameter types string randomitemvector arr )/returns random item in arrinefficient average illustrates an ideal use of call-by-value if we make call double averagexy )then call-by-value copies into ay into band then executes the code for the average function definition that is fully specified elsewhere presuming that and are local variables inaccessible to averageit is guaranteed that when average returnsx and are unchangedwhich is very desirable property howeverthis desirable property is exactly why call-by-value cannot work for swap if we make call swapxy )then call-by-value guarantees that regardless of how swap is implementedx and will remain unchanged what we need instead is to declare that and are referencesvoid swapdouble adouble )/swaps and bcorrect parameter types with this signaturea is synonym for xand is synonym for changes to and in the implementation of swap are thus changes to and this form of parameter passing has always been known as call-by-reference in +in ++ this is more technically call-by-lvalue-referencebut we will use call-by-reference throughout this text to refer to this style of parameter passing the second problem with call-by-value is illustrated in randomitem this function intends to return random item from the vector arrin principlethis is quick operation consisting of the generation of "randomnumber between and arr size()- inclusivein order to determine an array index and the returning of the item at this randomly chosen array index but using call-by-value as the parameter-passing mechanism forces the copy of the vector vec in the call randomitem(vecthis is tremendously expensive operation compared to the cost of computing and returning randomly chosen array index and is completely unnecessary normallythe only reason to make copy is to make changes to the copy while preserving the original but randomitem doesn' intend to make any changes at allit is just viewing arr thuswe can avoid the copy but achieve the same semantics by declaring that arr is constant reference to vecas resultarr is synonym for vecwith no copybut since it is constit cannot be modified this essentially provides the same viewable behavior as call-by-value the signature would be string randomitemconst vector arr )/returns random item in arr this form of parameter passing is known as call-by-reference-to- -constant in ++but as that is overly verbose and the const precedes the &it is also known by the simpler terminology of call-by-constant reference the parameter-passing mechanism for +prior to ++ can thus generally be decided by two-part test