9.9 Subprograms (Functions)
This lesson introduces subprograms as reusable building blocks of a computer program. It covers the structures of both built-in and user-defined functions, the mechanics of transferring data using parameters and return values, and managing variable scopes such as local and global variables.
ප්රධාන සංකල්ප
- Subprograms
- A self-contained block of code designed to perform a specific task that can be stored and reused within a program.
- Built-in Subprograms
- Pre-programmed functions already provided by the programming language environment for immediate reuse.
- User-Defined Subprograms
- Custom subprograms written by the programmer to perform specific tasks when no built-in subprogram is available.
- Parameter Passing by Value
- A data transfer method where the actual value of an argument is copied into the function parameter, meaning changes within the function do not affect the original data.
- Parameter Passing by Reference
- A data transfer method where a reference (address) to the actual variable is passed to the function parameter, allowing the function to directly modify the original variable's value.
- Local Variables
- Variables declared inside a specific subprogram that are only accessible and active within that subprogram's scope.
- Global Variables
- Variables declared outside of any subprogram that can be accessed and modified throughout the entire program.
- Return Values
- The output values passed back from a subprogram to the main program or calling scope once its execution is complete.
MCQ කට්ටල
MCQ 12විභාගයේදී
- Trace-running Python code containing local and global variable scopes to determine outputs.
- Writing custom functions (user-defined) with parameter passing and return values in written exams.
- Distinguishing between parameter passing by value and by reference in MCQ and structured questions.
