Types of Function
- system defined/library/inbuilt
- user defined
Advantages Of Function
=> A function is created once but used many times, often from more than one program.=> It reduces duplication within a program.=> Debugging and testing a program becomes easier when the program is subdivide.
How to define Function
A function will be executed by a call to the function.
Syntax
function function_name( )
{
code to be executed;
}
There are 3 types of variables i.e used inside a function
- Local
- Global
- Static
Local Variable
=> Local variables are always initialize inside the function body.
=> Local variable cant work outside function body.
Global Variable
=> Global variables are always initialize outside the function body.
=> Global variable work inside the function body as well as outside function body.
=> To access Global variable we have to use global keyword.
Static Variable
=> When a function is completed, all of its variables are normally deleted.
=> However, sometimes you want a local variable to not be deleted then use static keyword.
