What is default argument, C/C++ Programming

Assignment Help:

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);

}

 

 


Related Discussions:- What is default argument

Inbuilt functions in cpp, Inbuilt Functions i).  Functions to manipulate...

Inbuilt Functions i).  Functions to manipulate strings The cstring library defines many functions to perform some manipulation operations with C-styled functions. The followi

Program to determine the number is prime or not, Write a function to determ...

Write a function to determine whether a number is prime: it will return true if the input is prime and false otherwise. Use it to see whether -7 is prime.

How are postfix and prefix versions of operator++ , How are postfix and pre...

How are postfix and prefix versions of operator++ () differentiated? A: The postfix version of operator++ () contain a dummy parameter of type int. The prefix version does not c

Write a haskell program, Write a Haskell program that calculates a balanced...

Write a Haskell program that calculates a balanced partition of N items where each item has a value between 0 and K such that the difference between the sum of the values of first

Pebble merchant, having 2 arrays and 3killograms of pebbles are needed conv...

having 2 arrays and 3killograms of pebbles are needed converting an area of 1 square meter the rate of pebble is $5 per killograms

Define statements to define the constants, the problem description. The ...

the problem description. The order of the C Program should be as follows: Variables and constants Use #define statements to define the constants. Use arr

Bus Connection, how to explain working of bus connection

how to explain working of bus connection

What does this mean that "friendship isn''t transitive, What does this mean...

What does this mean that "friendship isn't transitive, inherited or reciprocal"? A: As I grant you friendship access to me doesn't grant your kids automatically access to me, do

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd