In this tutorial, we will be discussing a program to understand default arguments in C++.
Default arguments are those which are provided to the called function in case the caller statement does provide any value for them.
Example
#include<iostream>
using namespace std;
//function defined with default arguments
int sum(int x, int y, int z=0, int w=0){
return (x + y + z + w);
}
int main(){
cout << sum(10, 15) << endl;
cout << sum(10, 15, 25) << endl;
cout << sum(10, 15, 25, 30) << endl;
return 0;
}Output
25 50 80