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
A more advanced data type is the structure; here we can define a template as a collection of different variables e.g.     struct birthdate   {     int month;     int day;

Question A bank normally updates it's clients accounts at the end of each month.Of the two types of bank accounts:savings and checking, a client must maintain a minimum balance

C Program for SORTING # include stdio.h> void main() {           char a;           int *p;           int i,j,temp;           clrscr();           p=&i;

#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.   #include float start_poi

S y m b o li c c o n s t a n t : c on s t m a x = 1 0 0 ; T h e d e f a u l t d a t a t y p e w i l l b e i n t e

A company needs 200 pencils per year . you cannot simply use this price as the cost of pencils two years from now. Because of inflation the cost is likely to be higher than it is

limitation of function

pls say code for this above..

Define Commonly Used Built-in Library Functions? Comprise opened a file pointer you will desire to use it for either input or output. The C language supplies a set of functions