Function


What is Function?

Function is self-contained block of statement that perform coherent task as you wish.

There are two type of Function.

Pre-define Function:- cin,cout,getch,clrscr.
user-define Function:- user make Function.

Why use Function?

1. The use of Function is basically depend upon memory management.
2.It take less space in Ram.
3. Function divide the program in small part.
4. it reduce the re-write instruction in main program.

Function basic term

1. Function declaration.
2. Function definition.
3. Function Call.

Example

Void sum(int , int); //function declaration
void main()
{
Sum(a,b); // function call
Getch();//pre-define function
}
Sum(int a, int b)//define
{   int t;
   t=a+b;
}

Call By reference

In which we pass the reference variable as a argument.
For ex:-
int sum(int , int); 
void main()
{
Sum(&a,&b); // function call
Cout<<“the sum is “<<sum(&a,&b);
Getch();//pre-define function
}
Sum(int *a , int *b)//define
{   int t;
   t=*a+*b;
}


Comments