Functions and Procedues Flashcards
What is a function and what are its characteristics?
A function is a self-contained block of code, that can be invoked multiple times throughout a program, its characteristics include the following:
1. Modularity: Fuctions allow code to be broken down into smaller parts that perform specific tasks
2. Reusability: Once a function is defined it can be used multiple times throughout a program
3. Input/Output: Functions take in inputs as parameters and can return output
4. Scope: Variables created within a function, can only be accessed from within that function
5. Signature: Functions have a signature that includes their: Name, Input Parameters, and the data type of the value they return
What are some advantages of functions?
- They make modularity possible making code more readable, maintainable and manageable
- They are reusable, which reduces code duplication
What are the types of functions that exist?
There is 3 main types of functions and many others, the main three are:
1. Built-in functions: These are functions provided by a programming language or its standard libraries
2. User-defined functions: These are functions created by the programmer
3. Library functions: These are functions provided by a library that is not part of the standard libraries of the programming language
4. Other types of functions include: Recursive functions, Lambda functions, Higher-order functions, e.t.c