PPL UNIT-3 Notes

https://drive.google.com/file/d/1Rvnzyw3G6MvikDUyFNRhHNgZxizRvzeU/view?usp=sharing https://drive.google.com/file/d/1BiZKTvwQ7EA8TqHH8wtSeFYquzY1MAFs/view?usp=sharing












Subprograms, also known as procedures or functions, are fundamental building blocks in programming, offering reusability of instructions and reduction in coding time and memory space. Procedures do not return any value, while functions are subprograms that return a value. A subprogram is characterized by having only one entry point and control always returning to the caller upon termination.

A crucial aspect of subprograms is data access, achieved either through direct access to non-local variables or parameter passing. Parameter passing involves formal parameters (used in the function definition) and actual parameters (used in the function call). Conceptual models for parameter passing include "In mode" (receiving data), "Out mode" (transmitting data back), and "Inout mode" (doing both). Implementation models include Pass by Value, Pass by Result, Pass by Value-Result, Pass by Reference, and Pass by Name. The document also covers advanced topics like function overloading and generic subprograms (polymorphic subprograms). Function overloading allows multiple definitions for the same function name, differing in their parameter types. Generic subprograms take parameters of different datatypes and support parametric polymorphism, as seen in languages like C++ with function templates. Finally, the concept of co-routines, a special type of subprogram with multiple entry points and a symmetric unit control model, is introduced.

Here are 5 key bullet points of the specific topics covered with a brief definition for each:
  • Subprogram: A fundamental building block of a program, designed for reusability of instructions, with execution terminating and returning control to the caller.
  • Parameter Passing: A method for subprograms to access data, involving formal parameters (in definition) and actual parameters (in call). Implementation models include Pass by Value, Pass by Result, Pass by Reference, etc..
  • Function Overloading: Allows for more than one definition for a function name, provided the subprograms are in the referencing environment.
  • Generic Subprograms (Polymorphic Subprograms): Subprograms that can take parameters of different datatypes, supporting parametric polymorphism. Examples include C++ function templates.
  • Co-routines: A special type of subprogram with multiple entry points and a symmetric unit control model, where execution often partially completes and transfers control to another co-routine (using a "resume" call instead of a "call").

Comments