For Example , Suppose you have to check 3 numbers (531, 883 and 781) whether it is prime number or not. The required functionality is not available as a library function either in the standard C library or in the additional libraries supplied with the C compiler. Function definition consists all the code required for its implementation.Now we write function definition for the all the examples that are used while declaring function prototypes.In this example, values are received in x and y, we add them and store in variable sum and finally we return value of sum.Alternatively, we can use return keyword without returning any value to transfer control from called function to calling function like this:After declaring and defining user defined function, it can be used when needed.

Here are all the parts of a function − 1.

These are the formal arguments used in function definition which are used for receiving data).


Declaration of function informs the compiler about the existence of function and it will be defined and used later. Since these variables contain actual data which are required for the functioning of user defined function. Function Name− This is the actual name of the function. Every C program is combination of one or more functions. While creating a C function, you give a definition of what the function has to do.

The program control is transferred to the calling function after the return statement.The type of value returned from the function and the return type specified in the function prototype and function definition must match.You have successfully subscribed to our newsletter.You have successfully subscribed to our newsletter. Return Type − A function may return a value.
The Some functions performs the desired task without returning a value which is indicated by All definitions and statements are written inside the body of the function.Return statement returns the value and transfer control to the caller.To avoid ambiguity, we should not use the same name for functions arguments and the corresponding parameters in the function definition.Function definition inside another function results in a syntax error.

Such functions are called 1. 34.67) will be copied to variable x and y (Confused?

This comma separated list of variables which contains actual value is known as Now we make function call for all the functions that are declared and defined in the examples of function prototype and function definition sections.Here user defined function my_sum() is called with two values num1 and num2 which are of type float because function my_sum() requires two values of type float for its functioning which is defined and declared in prototypes and definition sections. In this case, the return_type is the keyword void.

As functions are defined by users, they are called user-defined functions.

The required functionality is not available as a library function either in the standard C library or in the additional libraries supplied with the C compiler. Functions are the basic building blocks of C programs.Every C program is combination of one or more functions. Using function by providing data required for its functioning is known as Here, var1, var2, ......, varN contains some value that are being passed to user defined functions. Value returned by my_sum() function is assigned to variable result.Here user defined function message() is called without any arguments because, in prototype and definition section, it is declared and defined in such a way that it does not require any arguments. A function is a single comprehensive unit (self-contained block) containing a block of code that performs a specific task. Remember semicolon at the end of function prototype.

For better understanding of arguments and return in functions, user-defined functions can be categorised as: When a function is called, these statements are executed until a return statement is encountered or all the executable statements are executed.