Function Introduction
Function is a block of code that performs a specific task and has its own scope. It is a basic building block in c programming.
All c programs have at least one function in a program for example main() function and every function has its own scope.
A function can also be referred as a method or a sub-routine or a procedure, etc.
Uses of function
-
Functions are used for understandability, re-usability, so that you don’t have to write same code again and again.
-
We can use the functions any number of times in a program.
-
Massive programs can be tracked when the program is divided into functions.
Parts of function
There are 3 important parts of function
-
Function declaration/prototype – this tells the compiler about the name of the function,
-
function parameters( type of value the function will accept) and
-
return type of function(what type of value the function will return)
-
Function definition – In this part you will define what the function will do, function body.
-
Function call – In this part you will use the function in the program where it is needed, at that time you don’t have to write the code again.
Syntax of function
return_type function_name( parameter list) { body of the function }