+ 1
What's wrong with this code?? Is it necessary to set default value to each parameter, if we set any value default??
#include <iostream> using namespace std; int sum(int a=42, int b) { int result = a + b; return (result); } int main() { int x = 36; int y = 24; //calling the function with both parameters int result = sum(x, y); cout << result << endl; //calling the function without a result = sum(x,y); cout << result << endl; return 0; } its showing error that it should have default value of "b" also.
5 odpowiedzi
+ 4
if you will put a default value to a parameter you need to put that variable at the final of the parameter list so it should be int sum( int b, int a = 42 ) ...
+ 2
ya rte radhika
+ 1
a=42
+ 1
radhika where u from
0
no , its not necessary but actually if you are giving value to a parameter then it is must to also give the value to the parameter in right side