1.

A function is defined as follows int sum (int a, int b = 2) {return (a + b);} Check whether each of the following function calls is correct or wrong, Justify your answer 1. cout<<sum (2,3);2. cout<<sum (2);3. cout<<sum ();

Answer»

Here the function is declared with one optional argument. So the function call with minimum one argument is compulsory.

1. It is valid. Here a becomes 2 and b becomes 3. 

2. It is also valid . Here a becomes 2 and b takes the default value 2. 

3. It is not a valid call. One argument is compulsory.



Discussion

No Comment Found

Related InterviewSolutions