Functions
Functions
int main()
{ int i,maxv,x;
cout<<"input ten integer numbers";
cin>>maxv;
for(i=1;i<10;i++)
{
cin>>x;
maxv=maxno(maxv,x);
}
cout << "maximum value=" <<maxv<< endl;
return 0;
} Lec. Sahar Khalid
Call by Reference
Passing arguments by reference uses a different mechanism. Instead of a value
being passed to the function, a reference to the original variable, in the calling
program, is passed. (It’s actually the memory address of the variable that is
passed). this provides a mechanism for passing more than one value from
the function back to the calling program.
Reference parameters are indicated by the ampersand (&) following the data
type:
The function declaration echoes the usage of the ampersand in the definition:
void intfrac(float, float&, float&); // ampersands in prototype
While intpart and fracpart are passed by reference, the variable number is
passed by value.