GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

function overloading

int f ( int x, int y = 10) {

    return x+y;

}

in the snippet, what is the meaning of int y = 10 and why it is written like so?? 

asked Oct 4, 2016 by bambhole

1 Answer

This is called default parameter, in which you set a default value for the variables. Suppose you call the function above as follows,

f(1,2), then it will take x=1 and y=2;

f(1), then it will take x=1 and automatically assign the default value to y , i.e y = 10.

So, in case you are not passing any value for that, the default value comes in action. 

Summary:- 

EXAMPLE:- 
void point(int x = 3, int y = 4);
 
point(1,2); // calls point(1,2)
point(1);   // calls point(1,4)
point();    // calls point(3,4)

Hope it helped. Do let me know if there is any confusion. Thank You for asking questions.

up vote it if you are satisfied by the answer.

answered Oct 5, 2016 by Mazhar MIK
...