Wednesday, 14 December 2016

Functions in C++

A function is a named block of code that performs some action.The statements are written in a function are executed when it is called by its name. Each function has a unique name.Functions are the building blocks of C++ programs. Functions are  easier to write, modify and maintain. Functions can be reused and reduce programming time. The encapsulate piece of code to perform specific task again and again without writing the same code again. They are used to perform tasks that are repeated many times.
The functions provide a structured programming approach. It is modular way of  writing programs. The whole program logic is  divided into number of smaller modules or functions. The main function calls these functions when they are needed to execute.

Importance of functions:

A program may need to repeat the same piece of code at various places. It may be required to perform certain tasks repeatedly. The program may become very large if  functions are not used. The piece of code that is executed repeatedly is stored in a separate function. The real reason of using functions is to divide a program into different parts, These parts of a program can be managed easily.

Advantages of Functions:

Some advantages of functions are :

1. Easier to Modify:

Each function has a unique name is written as an independent block. If there is any error in the program, the change is made to particular function in which error occurs. A small function is easier to modify than a large program.

2. Easy to Code:

A  lengthy program can be divided into small functions, It is easy to write small functions instead of writing one long program. A function is written to solve a particular problem. It makes programming easy.

3. Easier to Maintain:

Functions are easier to maintain than one long program. Each function contains independent code. A change in the function does not affect other parts of program.

4. Less Programming Time:

A program may consist of many functions. These functions are written as independent program. Different programmers can work on different functions at the same time. It takes far less time to complete the program.

5. Reusability:

The code written in functions can be reused as when required . A function but can be executed many times. A functions is written to solve a particular problem. Whenever that problem has to be solved, the function can be executed.



No comments:

Post a Comment

If you have any doubt please let me know

Methods in JAVA Language

 In general, a way may be thanks to perform some task. Similarly, the tactic in Java may be a collection of instructions that performs a sel...