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
Do you have any solution on this activity?

There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that

A: In C++ there is a main difference among a template and a macro. Merely a macro is a string which the compiler replaces along with the value that was defined. For example #define

Using a Friend Using a friend function is quite easy. The following example explains a friend function to access members of two classes. class Bclass;

Differentiate between functions getch () and getche (). - Both functions accept a character input value from user. - When getch () is used, key that was pressed won't appear

program to enter 5 values in queue and remove value one by one from queue.

Write a function that takes an array as the argument and returns the second largest element. Bonus (+5): Write a function that takes an array and a number n as arguments and return

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 tw

The project will include Arena models (only .doe files) and MSWord document for the report. Thereport must contain the following sections: 1. Introduction: (a)    Statemen

In the final project assignment you are asked to develop an OOP C++ class hierarchy for derivative pricing, using the binomial tree and Black-Scholes option pricing methods. You wi