Home » Learn C++ » Functions in C++

Functions in C++

Functions in C++:

            A function is a set of instructions that are designed to perform a specific task. A function is a complete and independent program. It is executed by the main function or any other function of the program to perform its task.

            The functions are written to write the code of a large program by dividing it into smaller units. When a program is more than a few hundred lines, it becomes difficult to follow. In this situation, the program is divided into smaller independent units. These smaller units are coded as functions.

            The functions are also written to avoid replication of a code in the program. In large programs, one often has to execute a piece of code several times. Instead of writing the code several times, the code is written only once as a function and this function is called to execute its code.
Functions are of two types: built-in functions and user-defined functions.

 

Built-In-Functions:

            The functions that have already been defined as a part of the language and can be used in any program are called built-in functions. The built-in functions are provided for general use.

 

User-Defined Functions:

            The functions created by a user are called user-defined functions. These functions are written as a part of a program to perform a specific task. These functions are written for a specific use.
A user-defined function has three parts. These are:
• Function Declaration (Prototype)
• Function Definition
• Function Calling

Other Topics

comment closed

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Copyright © 2010 Information Village. All rights reserved.