Chapter 5 Procedure activations 过程活动要点 参数传递机伟 宏扩展
Chapter 5 Procedure Activations 过程活动要点 ◼参数传递机制 ◼宏扩展
PROCEDURES(过程) When a procedure is called, the body is executed. Each execution of the body is called an activation of the body. Two forms of procedures: functions Functions extend the built-in operators of a language. procedures Procedures extend the built-in actions or statements
PROCEDURES(过程) When a procedure is called, the body is executed. Each execution of the body is called an activation of the body. Two forms of procedures: • functions Functions extend the built-in operators of a language. • procedures Procedures extend the built-in actions or statements
ELEMENTS OF A PROCEDURE 过程的要素 A procedure declaration makes explicit the elements or parts of a procedure: procedure name(过程名), a name for the declared procedure foma/ parameters(形式参数) placeholders for actual parameters result type(返回值类型), which is optional ocedure body(过程体), consisting of local declarations and a statement
ELEMENTS OF A PROCEDURE 过程的要素 A procedure declaration makes explicit the elements or parts of a procedure: • procedure name(过程名), a name for the declared procedure • formal parameters(形式参数), placeholders for actual parameters • result type(返回值类型), which is optional • procedure body(过程体), consisting of local declarations and a statement
HE ELEMENTS OFA FUNCTION PROCEDURE FORMAL RESULT NAME PARAMIETER TYPE function square(x: integer): integer; PROCEDURE egll BODY sguare:II ell
THE ELEMENTS OF A FUNCTION
A COMPLETE PASCAL PROGRAM WITH TWO FUNCTIONS, SQUARE AND AREA program trap(input, output; var result: real function square(x: integer): integer: begin square.dx end function area( a, b: real function f(x: real): real): real; DegIn dre:=(b-a)*(f(a)+f(b)/2 en d begin result: area(2, 5, square) writen 2, 5, result en d 带函数参数
A COMPLETE PASCAL PROGRAM WITH TWO FUNCTIONS, SQUARE AND AREA 带函数参数