Sometimes a function can has no implementation Terminology A function is

Sometimes a function can has no implementation

This preview shows page 8 - 16 out of 27 pages.

Sometimes a function can has no implementation.
Terminology A function is invoked by a function call function call / function invocation function invocation int z = Max(x, y) ; A function call specifies The function name function name The name indicates what function is to be called int z = Max (x, y); The actual actual parameters parameters to be used in the invocation The values are the information that the called function requires from the invoking function to do its task int z = Max( x , y );
Terminology A function call produces a return value The return value is the value of the function call int z = Max(x, y) ; A temporary memory called activation record activation record is allocated to maintain the local objects of the invocated function and other information for every function call. Even main() has a activation record
Invocation Process Invocation Process Main flow of control Allocate memory of Activation Record for fun() fun() Save the address of the main flow of control and the value of registers Free the memory of Activation Record for fun() Actual parameters are passed to formal parameters and execute the body of fun(). Restore address of the main flow of control and the value of registers 1 7 2 6 5 4 3 8
Invocation Process Flow of control is temporarily transferred to the invoked function Correspondence established between actual parameters of the invocation with the formal parameters of the definition cout << " Enter number: " ; double a; cin >> a; y = f( a ); cout << y; Value of a is given to x double f(double x ) { double result = x*x + 2*x + 5; return result; }
Invocation Process Flow of control is temporarily transferred to the invoked function Local objects are maintained in the invocation’s activation record. cout << " Enter number: " ; double a; cin >> a; y = f( a ); cout << y; Activation record is large enough to store values associated with each object that is defined by the function double f(double x ) { double result = x*x + 2*x + 5; return result; }
Invocation Process Flow of control is temporarily transferred to the invoked function Other information may also be maintained in the invocation’s activation record. cout << " Enter number: " ; double a; cin >> a; y = f(a); cout << y; Possibly a pointer to the current statement being executed and a pointer to the invoking statement double f(double x) { double result = x*x + 2*x + 5; return result; }
Invocation Process Flow of control

You've reached the end of your free preview.

Want to read all 27 pages?

Stuck? We have tutors online 24/7 who can help you get unstuck.
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes