C++ Programming | Functions 1

Functions In C++

Definition:
A function is a group/block of statements written to perform a specific task.

Advantages:

• Function helps us to make the program modular in nature.
• Function helps us to divide a large program into a number of smaller programs/modules.
• Different tasks of the large program can be performed by small programs/modules/functions.
• It is easy to debug the program when functions are used.
• Reusability of code. Code once written can be reused again and again. Thus saving a lot of time and space.

Important Points

• The function which calls another function is called the “calling function”.
• The function which is called is known as the “called function”.
• A function can call another function(any number of functions) from within itself.
• The process when a function calls itself is called recursion.

Classification of functions

Inbuilt functions:

Inbuilt functions are the functions which are already present in the system. We don’t have to write programs related to them, we have to just use them.
Examples:
Character functions
String functions
Math functions
Date functions
Time functions

User-defined functions:

UDF’s are the functions made by the programmer as per requirement. i.e. to perform a specific task.

Call By value:
In call by value, we deal with actual values.
Call By reference:
In call by reference, we deal with address i.e. pointers.