Functions Flashcards
Why do we use functions
To perform tasks.
Advantages of using functions
- Code reusability
2. Code optimization.
How are functions (code reusable)
When you create a function in C++, you can call it many times. So we don’t need to write the same code again and again.
How do functions optimize code
We don’t need to write much code.
What are the two categories of functions
- Library functions
2. User- defined functions
What are library functions
these are functions declared in the C++ header files.
What are user defined functions ?
These are functions created by the C++ programmer.
What is the syntax of creating a function
return_type function_name(datatype parameter) { // code to be executed }
What are the two ways to pass value or data to a function ?
- Call by value
2. Call by reference.
What is call by value
In call by value the original value is not modified
What is call by reference
In call by reference the original value is modified because we pass reference (address)
Differences between call by value and call by reference
in call by value changes made inside the function is not reflected on other functions.
Whereby in call by reference changes made inside the function is reflected outside the function.
What is a recursion function ?
This is when a function is called within the same function.