Posted by yanib on 2025-03-16 08:45:53 |
Share: Facebook | Twitter | Whatsapp | Linkedin Visits: 186
A function is a self-contained block of code that performs a specific task. It helps to break a program into smaller, manageable parts. Functions are used to perform repetitive tasks, improve code organization, and make the program easier to understand and maintain.
printf()
, scanf()
).A function that doesn't take any input (arguments) and doesn't return anything.
This function takes arguments (input) but does not return any value.
This function accepts arguments and returns a value.
In this method, the actual value of the arguments is passed to the function.
In call by value, the changes made inside the function do not affect the original variables.
In this method, the address of the argument (using pointers) is passed, so changes made inside the function will affect the original variable.
In call by reference, the changes made to the variables inside the function reflect in the calling function as well because we are passing their addresses.
A recursive function is a function that calls itself. Recursion is typically used to solve problems that can be broken down into smaller, similar problems.
Here’s an example of a recursive function to generate the Fibonacci series:
In this program, the Fibonacci series is calculated using a recursive function (fib
), which calls itself with smaller values of n
until the base case is reached.
printf()
, scanf()
).
I hope this helps! Let me know if you need further clarifications or more examples!