Function and Procedure Calls

Function and Procedure Calls - called, and each argument...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Function and Procedure Calls A function call has the form <function-name> ( <arguments> ) // this is an expression and a procedure call has the form <procedure-name> ( <arguments> ) ; // this is a statement where <arguments> is a sequence of expressions separated by commas. The method call may have to be preceded by an expression that indicates where the method is. For example, Math.sqrt(7) calls static function sqrt in class Math. s.length() calls function length of the object whose name is in variable s. s.substring(3,5).length() first calls the two-parameter function substring of the object whose name is in s to produce a second String object and then calls function length of that second object. The number of arguments must equal the number of parameters of the method being
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: called, and each argument type must be the same as or narrower than the corresponding parameter type. A method call is executed as follows this is explained in more detail in a later lecture: 1. Create the parameters and local variables of the method being called. 2. Assign the values of the arguments to the corresponding parameters. 3. Execute the method body. 4. Erase the parameters and local variables and, if this is a function, return the value of the expression of the return-statement that terminated the method body. From the above, you can see that the arguments are evaluated once and their values are stored in the parameters. In the method body, storing a value in a parameter has no effect on the corresponding argument. 2005 Cornell University...
View Full Document

This note was uploaded on 07/07/2008 for the course CS 101 taught by Professor Gries during the Spring '08 term at Cornell University (Engineering School).

Ask a homework question - tutors are online