Mar 23, 2007

Default Argument Function in C++

default argument function : In this program function add have two parameters and one of them is default argument and has fix value 10. if this argument is passed when calling this function default value of the function will be omited. If this value is not passed then default value
is used as a function argument.

#include<iostream.h>
#include<conio.h>
class demo
{
public :
void add(int a,int b=10) // value of b is default.
{
int c=a+b;
cout << c <<endl;
}
};

main()
{
clrscr();
demo d1;
d1.add(20); // value of b will be 20 and default value if omited.
d1.add(); // value of b will be 10 it means default value is used.
getch();
}

No comments:

Post a Comment

Infolinks In Text Ads

Total Pageviews

Powered by Blogger.

Dont Forget To Follow Us

Blog Archive