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

Inheritance is the process of forming new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class,

THIS PROGRAM IS TO MULTIPLY THE TWO COMPLEX NO.S GIVEN BY THE USER #include #include #include struct complex     {     int real;     int imag;     }; void main()  {  clrs

Example of structure: struct item {                 int element;                 node_ptr next; }; typedef node_ptr stack; stack create(void) {

Write a Program that illustrate union declaration? A C program encloses the following union declaration: union id { char color[12]; int size; } shirt, blouse; At this

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Create a program that will accept 3 numbers. The first number (num1) is the common difference and the second number (num2) is the starting number and the 3rd number (num3) is the m

Deliverables: you are required to upload your c code in the assignment dropbox set in Moodle. You are supposed to work with Linux gcc compiler and pico editor for compiling via the

explain Storage management: free storage pool, garbage collection, compaction, boundary tag method; Hash tables and hashing functions

program of area under integration