Q:

C++ program to demonstrate example of Default Argument

0

C++ program to demonstrate example of Default Argument

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Default Argument example in C++.

/*C++ program to demonstrate example of Default Argument.*/
#include  <iostream>
using namespace std;
 
//Default argument must be trailer.
int sum(int x, int y=10, int z=20)
{
    return (x+y+z);
}
 
int main()
{
    cout << "Sum is : " << sum(5)       << endl;
    cout << "Sum is : " << sum(5,15)    << endl;
    cout << "Sum is : " << sum(5,15,25) << endl;
    return 0;
}

Output

    Sum is : 35
    Sum is : 40
    Sum is : 45

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Most popular and Searched C++ solved programs with Explanation and Output

Similar questions


need a help?


find thousands of online teachers now
C++ program to demonstrate methods of passing argu... >>
<< C++ program to demonstrate example of Inline Funct...