FUNCTION
A function is a self-contained block of code that can perform a particular task.
The function is also known as subroutine or sub-section of a program.
Some facts:
A function’s structure contains a name, return type, arguments, and
function body.
Two types of functions are in C Program. 1- Standard Library Function
(Provided by C Compiler) and 2 – User Defined Function.
The special function called main ( ) is where program execution begins.
Raj K Baliyar Singh, Asst. Professor NIST (Auto)
Why are functions needed?
• Code reusability
• Program portability
• Maintaining large program become easier.
• Allow function recursion.
Types of Function
Standard Library Function
These functions are a wide range of pre-packaged functions. This function
performs a variety of tasks and are predefined in the standard library.
e.g.: clrscr(), printf(), scanf(), etc.
User-Defined Function
These are defined by the programmer, which can perform some specific
task.
e.g.: int add (int x, int y)
Parts of the Function
Raj K Baliyar Singh, Asst. Professor NIST (Auto)
Return Type:
A function return type tells the compiler which type of data will be returned
from the called function to the calling function.
The default return type of the function is an integer.
Function Name:
Valid name of the function.
If the function name contains two words, then there should not be any
space.
It always starts with a small letter, and should not contain any numbers in
the function name.
Arguments:
Arguments are passed to a function specify to the compiler, which types of
data will be transferred from the calling function to the called function.
There are two types of arguments: actual argument (pass from calling
function to called function), and formal argument (receive the values
passed from the calling function to the called function.)
Visit this Link to get more detail on C Programming
[Link]
Raj K Baliyar Singh, Asst. Professor NIST (Auto)