Example 1: C++ program for addition of numbers using a function
kw.cpp
#include <iostream>
using namespace std;
int add(int a = 7, int b = 8)
{
    return a + b;
}
int main()
{
    cout<<add()<<"\n";
    return 0;
}
Output
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out 15 kodingwindow@kw:~$
Example 2: C++ program for addition of numbers using a function
kw.cpp
#include <iostream>
using namespace std;
int add(int a, int b)
{
    return a + b;
}
int main()
{
    int i = 7, j = 8;
    cout<<add(i, j)<<"\n";
    return 0;
}
Output
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out 15 kodingwindow@kw:~$
Advertisement