Preview
Introduction to function in C Language
It is defined as named block of statements .
Advantages of function in C Language
- It is very easy to find and correct errors .
- It reduces complexity .
- Testing becomes easier.
- Bigger problems can be divided into smaller sections .
- They can be reused.
- Simple to understand a function based program.
- Memory can be used efficiently.
- un-ncessary repetition of code is reduced.
Creating a function in C Language
The syntax for creating a function is
Type Fname(Parameters)
{
Variables ;
:
:
Statements;
:
:
return( Value );
}
Type is the data types of value returned by function.
Fname is the functions name specified by the programmer.
Parameters are variables declared within parenthesis written after the function name. These variables are called parameters
Variables are declared within function body.
Statements is set of instructions which would run when function is called.
return is used to return a value from function.
Value is any valid variable, constant or expression. The return type of function will depend upon it. If it is of float type, the return type would be int and so on.