Introduction to function
It is defined as named block of statements .
- It is very easy to locate and correct errors .
- It reduces complexity of code.
- Testing of a program becomes easier.
- Bigger softwares problems can be divided into smaller sections using functions.
- Functions can be reused.
- It is simple to understand a function based program.
- Memory can be used very efficiently.
- Functions reduce un-ncessary repetition of code.
Creating a function
The syntax for creating a function is
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.
Best Books of C