← Sindh Board notes
AI draft — not yet reviewed by a teacher. Check with your teacher.
Computer Science · Class 10 · Chapter 12: Functions
8 min
Key points
- Function is a sub-program or sub-routine that performs a specific task and can be called from the main program
- Functions reduce program length, avoid repetition of code, and make programs easier to understand and debug
- There are two types of functions: Built-in functions (provided by C language) and User-defined functions (created by programmer)
- Function declaration tells the compiler about function name, return type, and parameters
- Function definition contains the actual code that executes when function is called
- Function call is used to execute the function from main program or another function
- Return statement sends value back to the calling function
- Parameters are values passed to function while arguments are actual values received by function
Definitions
- Function
- A function is a sub-program or sub-routine that performs a specific task and can be called from the main program or from another function
- Function Declaration
- Function declaration tells the compiler about the function name, return type, and parameters but does not contain the function body
- Function Definition
- Function definition contains the actual statements or code that executes when the function is called
- Built-in Functions
- Built-in functions are pre-defined functions provided by C language such as printf(), scanf(), sqrt(), pow() etc.
- User-defined Functions
- User-defined functions are created by the programmer according to program requirements to perform specific tasks
Worked example
Define function and determine whether the relation f = {(1,2), (2,4), (3,6), (4,8)} is a function or not. Also find its domain and range. (5 marks)
Definition: A function is a relation in which each element of the domain is paired with exactly one element of the range. Checking the relation: Each input value (1,2,3,4) maps to exactly one output value, so this is a function. Domain = {1,2,3,4}, Range = {2,4,6,8}
Common mistakes
- Students often confuse function declaration with function definition
- Forgetting to write return statement in functions that return values
- Not matching parameter types in function declaration and definition
- Writing function call without proper arguments
- Confusing built-in functions with user-defined functions in examples
Quick recap
A function is a special relation where each domain element maps to exactly one range element. Remember the vertical line test for graphs - if any vertical line intersects the curve more than once, it's not a function. Types include one-to-one (injective), onto (surjective), and bijective functions. Always write domain and range in proper set notation.
Generated by AI from Sindh Textbook Board material; review state: ai_unreviewed. MCQs, past-paper references and examiner notes are held back until a teacher has checked them.