MENU
Question -

What is the benefit of using default parameter/ argument in a function ? Give a suitable example to
illustrate it using C++ code.



Answer -

The benefit of using default arguments is that whenever there is no value supplied to the parameter
within the program, its default value can be used.
Example :

#include 
#include
int main()
int a,b=20,c; 
a=change(c,b);    
return a ;
}
int change(int a=10,b)
{
int temp; 
temp=a; 
a=b;
return temp; 
}
In the above example, change () assigns a value 10 to a because it is defined by default.

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×