Types of Functions in C
Types of Functions in C
Functions in C:
Functions are sub-programs that are used to compute a value or perform a task. They
can’t be run independently. In C language, there are two kinds of functions are exists.
Built-in functions
User-defined functions
1. Built-in functions:
Built-in functions are used to perform standard operations.
Example:
scanf(), printf()
2. User-defined functions:
User-defined functions are self-contained blocks of statements that are written by the
user to compute a value. It is used to compute and return the value of a specific data
type to the calling program.
Function Declaration:
The general syntax of a function declaration is given below :
type name(type argu1, type argu2, ......, type argun)
{
<local declaration>
----------
<Statement block>
----------
return (variable);
}
where type is the data type of the value returned by the function and arguments
expected.
argu1, argu2, ……, argun are the arguments that are variables that will receive the
values from the calling program. name is the name of the function by which the function
is called by the calling program.
Actual Arguments:
The arguments listed in the function calling statement that is called Actual Arguments.
Example:
Formal Arguments:
The arguments used in the function declaration that is called Formal Arguments.
Example:
Recursion:
A function calls itself again to compute a value that is called recursive function
or recursion. A function is called by the main program but in recursion, the same
function is called by itself repeatedly.
Example :
int fact(int x)
{
if(x==0)
return(1);
else
return(x*fact(x-1));
}
120