Introduction Of Function In C++

Now that you should have learned about variables, loops, and if statements it is time to learn aboutfunctions. You should have an idea of their uses.
 
Cout is an example of a function. In general, functions perform a number of pre-defined commands to accomplish something productive.
 
Function is a group of statements within a single unit. Basically, it is a set of statements grouped together. You may wonder what use a function is? Or you may ask why not write the entire program within the main function itself?
 
The reason is simple. Suppose, in your program, you have to repeat a certain procedure at different instances. Mean, a particular function has to be done in different parts of the program.
 
You could keep typing the code in all the places (making the program larger in size) or you could make use of functions concept. All you need to do is define the function once. Wherever you need to perform the function you just need to call it (the call statement is just one line).
 
The general syntax of a function is:
 
 
Return data type Function name (arguments);
 
The return data type specifies what sort of data the function will return to the calling function.
 
For example if return data type is int, then the function will return an integer value to the main or calling function.
 
If the return data type is void, this means that the function does not return any value.
 
Actually the above syntax is the syntax for function declaration. You’ll soon learn about it. Just read on…
 
There are three components of a function namely:
 
Function Declaration or Prototyping
 
Function definition and
 
Function call.