Functions In C
function initialization / definition:
here we define your functions with its entire logic. If we defied the prototype of the function then the function definition always defined after defining the prototype of the function.
syntax:
returntype_of_function function_name( arguments...){
//entire logic;
// return value;
}
example:
int sum( int a, int b){
int x;
x=a+b;
return x;
}
Here, In your example, we first define your function definition as int sum( int a, int b) here we write return type as int because at the end the function is going to return an integer value ( x ). Then we write name of the function as a sum and in parentheses, we specified arguments as int a and int b. That means your function is going to tack two arguments of integer type when we are calling the function.
More example on functions:
Recursion:
recursion means function calling it self. when function call it self in function definition it called as resursion.
example of recursive function:
- factorial of number
- fibonachi serese
- marge and quick sort
And many more...
lets understand recursion with example:
To understand recursion well lets understand first about stack
stack: stack is used to store value and for that stack follows certain rules as LIFO or FILO mean whatever last value is stored it give that value fist ( last in first out) and value that stored first it given at last( first in first out ) both are same in logic way.
Don't worry if you face any problem to understand stack it become more clear when we refer examples.
example:
Factorial of number: