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
The goto statement This statement can be used to branch to another statement of the program. This is rarely used as it violates the principle of structured programming. Though

Compound Assignment Operators Apart from the binary and the unary arithmetic operators, we also have compound assignment operators. These are +=, -=, *=, /=, %=. Using these op

Define some features of static storage class in c program? The features of a variable defined to contain a static storage class are as follows. Storage - memory Default

simple shopping cart

I want Skype Recorder Application + Setup + Sourcecode + NICE UI Project Description: i want an application built which will allow user to record skype audio or video calls


write a C rpogram that can display the transpose form of a ciphertext matrix.Prompt users to provide row and coloumn number of matrix.Then user will input plaintext and the program



Write a C program to calculate the output Y for a given value of X for the following formula   Y=X 2 + 2X +3   #include stdio.h   void main()   {   char promt;   float y,x