Default Arguments Assignment Help

Assignment Help: >> Functions, Arguments and Overloading - Default Arguments

Default arguments

One of the useful facilities available in C++ language is the facility to define default argument values for the functions.  Within the function prototype declaration, the default value is given. Whenever a call is made to a function without specifying an argument in which the program will automatically assign values to the parameters from the default function prototype   declaration.            Default arguments facilitate make simple development   and maintenance of programs.

Sample program

// default argument declaration

# include <iostream.h>

void sum (int a, int b, int c = 6, int d = 10);          //default argument initialization

void main( void)

{

int a,b,c,d;

cout<<"enter any two numbers\n";

cin>>a>>b;

sum(a,b);        //sum of default values

}

void sum(int a1, int a2, int a3, int a4)

{

int temp;

temp = a1+a2+a3+a4;

cout<< "sum="<< temp;

}

output of the above program

enter any two numbers

10 20

sum = 46

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd