UNIT-III: Subprograms and Blocks: Fundamentals of sub-programs, Scope and lifetime of variable,
static and dynamic scope, Design issues of subprograms and operations, local referencing
environments, parameter passing methods, overloaded sub-programs, generic sub-programs, design
issues for functions overloaded operators, co routines.
General Subprogram Characteristics
• Each subprogram has a single-entry point
• The calling program is suspended during execution of the called
subprogram
• Control always returns to the caller when the called subprogram’s
execution terminates
Basic Definition
• A subprogram definition describes the interface to and the actions of the
subprogram abstraction
• A subprogram call is an explicit request that the subprogram be executed
• A subprogram header is the first part of the definition, including the
name, the kind of subprogram, and the formal parameters
• The parameter profile of a subprogram is the number, order, and types of
its parameters
• There are two distinct categories of subprograms, procedures and
functions.
• Procedures: provide user-defined parameterized computation
statements.
Functions: provide user-defined operators which are semantically
modeled on mathematical functions.
• The protocol is a subprogram’s parameter profile and, if it is a function,
its return type.
• Function declarations in C and C++ are often called prototypes
• A subprogram declaration provides the protocol, but not the body, of the
subprogram.
• Parameter: A formal parameter is a dummy variable listed in the
subprogram header and used in the subprogram
• Argument: An actual parameter represents a value or address used in the
subprogram call statement.