Tuesday, September 7, 2010

How to use functions in Cplusplus

,
Why we are use Function?

Function is a block of task, In simple word we can say that it's block which we contain instruction or procedure. Which is very useful when we need some procedure or instruction block which execute process and less of development time for a software or solution any kind C and C++ program.


Types of Function

1. Parameterize Function
2. Non Parameterize Function
3. Friend Function
4. Virtual Function

Guidelines for using function.
1. Always define prototype
2. When we use friend function use friend keyword
3. In virtual function use keyword virtual

Example of Function in C plus plus


#include<iostream.h>
#include<conio.h>
Int main()
{
Clrscr();
Float sum (int,float);
Int a=20;
Float b=2.5;
Cout <<”sum=”<
Return 0;
}
Float sum (int  x,float  y)
{
Return (x+y);
}

OUTPUT
Sum = 22.5

0 comments to “How to use functions in Cplusplus”

Post a Comment