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.


// default values in functions


using namespace std;

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

int r;

return  (r);


int main  ()

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

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

return  0;






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
Define the Int Data Type of C Language? The int is used to define integer numbers. The Integers are whole numbers with a range of values supported by a particular machine and t

Explain the Working of strcpy Function? strcpy() : This function is meant to use to copy one string to another. The strcpy function as well accepts two strings as arguments.

In this we will take a closer look at the logic behind Object Oriented Programming.  Read through the pseudocode listed below and answer the following questions. Class Square

I want VLC Pitch Changing Addon Project Description: Required: Plugin to modify the pitch of running tracks in VLC without changing the speed. Skills required are C Progra

#include using namespace std; void print(int marks_arr[],int cnt) { int ind[cnt]; int i=0; int j=0; int k=0; int s=0; for(k=0;k { ind[k]=0; } int cnt1=0; for(i=0;i

Write a simple telephone book program that stores the names and phone numbers of your friends/acquaintances in a file. Your program should have the abilities to: a. Add entries (na

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

color representation 0,1,2,3,4,5,6,7...

program for factorial