Return type tells us about the type of value returned by the function. In the following example we are declaring a function named findArea having return type float and it takes two parameters length and width of type float.įloat findArea(float length, float width) Like variables, in C we have to first declare a function before calling it.įunction declaration is also known as the function prototype and it consists of 4 parts given below.
C++ FUNCTION PROTOTYPE CODE
This will help us in developing the code easily and will also help in testing and debugging in case of any error.Ī user defined function consists of three parts. Or we can divide the program into subprograms using function like findArea(). The idea is to break the program into modules (subprogram) and develop the program in small pieces and then join them together to solve the problem.įor example, if we have a program to find the area of a rectangle then we can either write the entire code inside the main() function. These subprogram are designed to perform specific task and hence it makes the code easier to develop, test and debug. User defined functions helps us to break our program into subprograms. Whereas, User defined functions are the ones that we have to write in order to use it. Library functions are already created and ready for use and we don't have to write it. The main() function is user defined function whereas, printf() and scanf() are library functions.ĭifference between Library and User Defined functions These are the functions created by the user like for example greetings() or displayResult() etc.
![c++ function prototype c++ function prototype](https://images.slideplayer.com/28/9373278/slides/slide_4.jpg)
![c++ function prototype c++ function prototype](https://i.ytimg.com/vi/NxjDjfS40N8/maxresdefault.jpg)
These are the functions that we get from the C library like strlen(), concat() etc. In this tutorial we will learn about functions in C programming language.Ī function in C is a block of code consisting of some statements that performs a specific task.įor example, we can have a greetings() function that will print greetings message whenever it is called.