What is default argument, C/C++ Programming

Default argument:

When the argument is missing then the function will read the default value of the missing

argument.  To make use of default argument functionality the argument must be initialized in the prototype or declaration.

Rules for declaring default argument:

1.   The default value must given from right to left arguments

2.   Cannot assign only the first argument as default when there is more than one argument.

3.   All the arguments may be default.

4.   When there is more than one argument the intermediate argument cannot be a default.

int f_def(int x, int y=20); // Default argument value initialized at prototype.

void main( )

{int a=10, b=15,c;

c = f_def(a, b); //The value of c is 15 c = f_def(a); // The value of c is 30

}

int f_def(int x, int y)

{ return (x+y);

}

 

 

Posted Date: 9/20/2012 7:47:52 AM | Location : United States







Related Discussions:- What is default argument, Assignment Help, Ask Question on What is default argument, Get Answer, Expert's Help, What is default argument Discussions

Write discussion on What is default argument
Your posts are moderated
Related Questions
#questi An array of n numbers is given, where n is an even number. The maximum as well as minimum of these given numbers need to be determined. Which of the following is true about


how do i print out invalid input?

d) a "static destructor" is a static member function of the class which accepts one argument - a pointer to the object of that class to be cracked. It is probably utilized along wi

write a program for convert numbers upto 9 to alphabet?Eg.now enter the inputis 666 means output is "0" lphabet

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

How must runtime errors be handled in C++ - Runtime errors in C++ can be handled using exceptions. - This exception handling mechanism in C++ is developed to handle errors i


By pressing ‘6’ (i.e. key’6’ one time) on the keypad, the mobile shows ‘m’ on display screen in write text message area

Want a scraping program created Project Description: We need to hire a professional developer to scrape the site for information such as *product title *Product Price