C++

Function

A function is a self contained block of statements that performs the particular task of some kinds. A function is a small program written by programmer itself or provided by system to perform a certain tasks.

Advantages of Function

  1. Reduces the size of the program by calling and using at different places in a program.
  2. Avoiding rewriting same code over and over
  3. different programmer can involve for developing complex system independently by dividing into small program  
Steps involving during function
  1. function declaration
  2. function call
  3. function definition

void display( );   // function declaration
main()
{
.....................
...................
display( );   //function call


}


void display( )
{
 ...........
............    // Function definition



}


When the function is called, control is transferred to the first statement in the function body. The other statements in the function body are then executed and control returns to the main program when the closing brace is encountered.


Function overloading

A function can be overloaded to make it perform different task depending on the arguments passed to it.

Comments

Popular posts from this blog

PROGRAM TO FIND SQUARE, CUBE, SQUARE ROOT AND CUBE ROOT OF GIVEN NUMBER

PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS

PALINDROME AND ARMSTRONG PROGRAMS