Predefined Function
- In-built functions are also called predefined or Library functions.
- In-built functions, different header files or processors have been created for each functions.
- There are lots of header files in C and they are grouped by different functions.
- If programmer wants to create your own header files too.
- Function declaration and definition is in header files.
Example:
User-defined function
User defined functions are those functions which programmer (you) create for yourself. Programmer can create as many functions as per your requirement.
Declaration of a function
When writing a function we need to tell the computer the name, the return type and the parameter(if any) of that function.
return-type – What kind of value will return when your function execution is complete, you define it by return type. If you are creating an addition program which adds 2 whole numbers then your return type is int.
function-name – this is the name of your function. These should be unique in the whole program. When you call the function, you write this name only.
list-of-parameters – These are the lists of variables that you will pass when calling the function. For example, if you are creating addition of function then you can pass 2 numbers or 2 variables as parameters, and then add them inside the function and show results. It is not necessary that you define parameters in all functions.
One thing you should always remember is that the function declaration statement is terminated from semicolon. But this does not happen with the function definition.
Function Definition
Function definition includes return-type, function-name, and list-of-parameters as in the function declaration. After that, those statements are written in the block of curly brackets that you want to execute.
Let’s see how
#include "stdio.h"
int add(int a,int b) //a,b are the parameters which can be provided while calling the function
{
int c;
c=a+b;
return c;//returns the integer value of the sum here
}