Functions


In C language a function is a block of code that performs a specific task and can be executed multiple times in different parts of the program. Every function has its unique name and may return a value to the calling program. It depends on the task that is performed. For example a function that adds two numbers will return the value of sum etc. A general form of a function looks as follows:
return_type function_name (argument, ... , argument_n)
{
statement1;
...
statement_n;
}

Return type informs about the type of data returned by the function. If the functions does not return any values the return type is set as void. Any function can have multiple parameters and their names are noted in the brackets next to the name of the function. The body of the function is a set of instructions that performed after the function is called and they are placed in the curly brackets below the function header. The variables declared within the function are available only for this specific function and are not accessible anywhere else within the code.
Example:
Function comparing two integer numbers and returning the bigger one.

int max (int a, int b)
{
if (a>b)
return a;
else if (b>a)
return b;
}