A function is a group of statements that together perform a task. Every C++ program has at least one compulsory function commonly known as the main() function.
How many types of function in C+?
There are two types of functions,
- the user defines
- built-in functions.
Built-in functions
Built-in functions are developed by the developers of the compiler when they develop the compiler software.
We just need to use them.
User defines functions
The user defines functions are needed to be declared, defined, and call by the user.
Simple C++ program to demonstrate User defineĀ function
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <iostream> using namespace std; int sum (int, int); int main(){ cout<<sum(4,7); cout<<"Welcome to T4Tutorials.com"<<endl; return 0; } int sum (int num1, int num2) { int num3 = num1+num2; return num3; } |
Output
11 Welcome to T4Tutorials.com
Dry Run and Explanation of User defineĀ function with SMT


Advantages of user-defined functions- C++
- User-defined functions help us to divide a big program into smaller parts.
- The smaller parts of the program have the following benefits;
- Easy to understand.
- Easy to modify.
- Easy to maintain.
- Easy to debug.
Some important concepts you must know while working on user-defined functions are mentioned below;
- Call by value
- Call by referenceĀ