Declaration :
void
AddVal(
int
iFirstVal,
int
iSecondVal=0);
Definition
void
AddVal(
int
iFirstVal,
int
iSecondVal)
{
int iVal = iFirst+iSecond;
cout <<
"Sum : "
<< iVal << endl;
}
int
main()
{
AddVal(1);
AddVal(3, 4);
}
1. Default Parameter should be last parameter.[Otherwise hot compiler will know which attributes should be omit.]
2. No default value allowed in definition. Default value should be given only in declaration.
3.
Default arguments can be provided for pointers to functions. For example:
int (*pShowIntVal)( int i = 0 );
No comments:
Post a Comment