Default Arguments In C++ Function
The default arguments are used when you provide
no arguments or only few arguments while calling a function. The default
arguments are used during compilation of program.
Fig: Default Arguments In C++ Function |
Program:
#include<iostream.h>
class
BCA;
int
sum(int a, int b=10, int c=20);
int
main()
{
cout<<sum(1)<<endl;
cout<<sum(1, 2)<<endl;
cout<<sum(1,2,3)<<endl;
return
0;
}
int
sum(int a, int b, int c)
{
int
z;
z=a+b+c;
return
z;
}
Output:
31
23
6
No comments:
Post a Comment