please read it hope u understand ... if any query ask me again..
why functions..:
every programming language contains a mandatory main()..
as the length of the program increases its difficult to handle the code for the programmer only in main() thats when functions were introduced..
it modularizes ur code and makes it easier for the programmer to decode it..
the basic syntax required is :
return-type function-name (parameters)
parameters are not compulsory...
FUNCTIONS :
there are 3 steps in using a function
1. function prototype also called as function declaration
2. function calling
3. function definition..
Function prototype:
it informs the compiler that there is some function used ahead in the program..
its concept is same as a variable declaration
eg. return-type example(parameters);
return-type specifies that WHAT the function will return
parameters list defines what kind of parameters are used..
Function calling :
syntax
function-name(parameters);
the above syntax will take the program flow to function definition
no need to mention the return-type here..
the parameters will be passed to it.
Function definition :
here's its the actual code of what a function should do is written..
return-type function-name(parameters)
a practical example:
suppose u want to order a pizza on phone ...
u get the phone directory mentioning the pizza shop's phone number....(thats function declaration )
u make call to him.. (thats function calling )
on the phone u mention which pizza u wish to have..(thats the parameters u pass)
how the pizza is to be made that's pizza chef's work/... thats function definition
definition is what the function is gonna perform..
and finally the return-type is ur pizza u get at home.....
hope u understand it buddy..
or else press F8 to understand the flow of program...
that will help u too