User define function or function calling in C

What is a function in C programming?

Function is like some task defined in a group of instruction. If we call the function, it's do something for us and sometimes return something.
For example, let's think about a factory which input some Raw material and process it, then give us some output. Like as a blending machine. We input water, ice, sugar, lemon and output is lemon juice.
In a function, there is some instruction and when we call it, ti give us some result according to the instruction.
Every c program must have at-least one function called main function looks like main(). There are many library functions in C, like as printf ( ); scanf( ); etc. Again we can write functions our-self.

Basic structure of a function:


* Return type: Return type is the kind of output of function. For blending machine, output is "lemon juice". So here return type is liquid.
* Function name: It's just the name of the function. Like as "blending machine".
* Parameter list: Parameter list is input list. Here water, ice, sugar, lemon.
* Body of the function: The instruction of processing our inputs. 

Example: 



Output:

Explanation :

In basic instruction:


is define as:


Here return type is integer. Parameter type is important. Here is two parameters a and b which are integer type. So we have to pass integer type argument as input.

Benefits of function:

If we need to do same processing in many place of our code, we have to write same code again and again. Like as if we need to add two number for several time, we can write a function and call it again and again.

Like as :



Output:

Another Example:



Output:


Hope it's help to understand function declaration and how to use function, make function.
Happy coding !!!

 Related Post:

Let's play with stars using C programming  

What is a function in C programming? Function is like some task defined in a group of instruction. If we call the function, it's do something for us and sometimes return something. User define function or function calling in C programming.