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
#questionHi, I am looking for help with the assignment, can you help..

Many modern cryptography algorithms require two numbers that are coprime, or sometimes referred to as relatively prime. Two numbers are coprime if their greatest common divisor is

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome


i have a project that is due this Wednesday and i was wondering if i can get help in doing it?

Get Reverse Engineer to Linux game routine analysis Project Description: I want a fast and efficient reverse engineer with good knowledge of assembly x86 language, strong rev

please answer the question of following Write a function that calculates the number of elapsed days between two dates. For example the days between Feb 3, 1970 and June 21, 1980? B

In this problem, you will write a program that implements two algorithms for performing exact inference given a Bayesian network, namely, enumeration and variable elimination. Your

what is c++ ?

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