Functions in C
The function in C language is also known as procedure or subroutine in other programming languages. To perform any task, we can create function. A function can be called many times. It provides modularity and code reusability.
Advantage of functions in C
There are many advantages of functions. 1) Code Reusability 2) Code optimization
Types of Functions
There are two types of functions in C programming:- Library Functions: are the functions which are declared in the C header files such as scanf(), printf(), gets(), puts(), ceil(), floor() etc.
- User-defined functions: are the functions which are created by the C programmer, so that he/she can use it many times. It reduces complexity of a big program and optimizes the code.

Declaration of a function
The syntax of creating function in c language is given below:return_type function_name(data_type parameter...) { //code to be executed }
Let's see a simple example of C function that doesn't return any value from the function. Example without return value:
void hello ( ) { printf("hello Catchmecoder"); }
int get ( ) { return 10; }
float get ( ) { return 10.2; }
Parameters in C Function
A c function may have 0 or more parameters. You can have any type of parameter in C program such as int, float, char etc. The parameters are also known as formal arguments. Example of a function that has 0 parameter:void hello ( ) { printf ("hello Catchmecoder"); }
int cube(int n) { return n*n*n; }
int add(int a, int b){ return a+b; }
Calling a function in C
If a function returns any value, you need to call function to get the value returned from the function. The syntax of calling a function in c programming is given below:
variable = function_name(arguments...);
1) variable: The variable is not mandatory. If function return type is void, you must not provide the variable because void functions doesn't return any value.
2) function_name: The function_name is name of the function to be called.
3) arguments: You need to provide arguments while calling the C function. It is also known as actual arguments.
Example to call a function:
hello(); //calls function that doesn't return a value int value = get( ); //calls function that returns value int value2 = add(20, 30); //calls parameterized function by passing 2 values
Example of C function with no return statement
Let's see the simple program of C function that doesn't return any value from the function.#include <stdio.h> //defining function void hello( ) { printf("hello Catchmecoder"); } void main( ) { hello( ); //calling a function hello( ); } Output hello Catchmecoder hello Catchmecoder
Example of C function with return statement
Let's see the simple program of function in c language#include <stdio.h> //defining function int square(int n) { return n*n; } void main( ) { int result1 = 0, result2 = 0; result1 = square(5); //calling function result2=square(7); printf("%d ",result1); printf("%d ",result2); } Output: 25 49