Default value functions, C/C++ Programming

Default Value Functions, When declaring a function we can specify a default value for each parameter. This value will be used if that parameter is left blank when calling to the function. This is done by assigning values to the arguments in the function prototypes. If a value for that parameter is not passed when the function is called, the default value is used, but if a value is specified this default value is stepped on and the passed value is used. 

Default arguments must always be the rightmost in a function list i.e. when calling a function with two or more default arguments and an omitted argument is not the rightmost argument in the argument list then all arguments to the right of that argument must be omitted.

Example:

// default values in functions

#include 

using namespace std;

int divide  (int a, int b=2);
int divide  (int a, int b)
{

int r;
r=a/b;

return  (r);

}

int main  ()
{

cout  << divide  (12);
cout  << endl;

cout  << divide  (20,4);
cout  << endl;

return  0;

}

 

Output

6

 

Posted Date: 8/21/2012 11:51:23 AM | Location : United States







Related Discussions:- Default value functions, Assignment Help, Ask Question on Default value functions, Get Answer, Expert's Help, Default value functions Discussions

Write discussion on Default value functions
Your posts are moderated
Related Questions

Hi is there any chance to get assignment for fresher tutor

Programming an odds betting website Project Description: We want someone to program a odds betting website, Require someone with experience and skills! Skills required are

convert BST into sorted doubly linked list

The size of () operator This is a pseudo-operator given by the language, which returns the number of bytes taken up by a variable or data type. The value returned by this opera

padovan string for n natural numbers p(n)=1,p(n)=2,p(n)=3 and use padovan formul to get output 1

O v e r l o a d i n g U n a r y Op e r a t o r s Us i n g F r i e n d F u n c t i o n cl a ss s i g n { i n t a ,

One person who is specialist at programming and solving problems with a computer Project Description: Potential computer, hardware, programming and software genius, I look

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

Based on the automobile's model year and weight, the city of Cebu determines the car's weight class and registration fee using the following schedule: Model Year Registration