ADVERTISEMENT
ADVERTISEMENT

Home » C++ programs » C++ basic programs

C++ program to demonstrate example of Default Argument

Default Argument is an important feature in c++, using default argument you can pass any argument default and can skip that argument while calling, in this example we will learn use of default argument.

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
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.