0

I dont understand default arguments

25th Aug 2016, 9:22 PM
David Arnold
David Arnold - avatar
2 Answers
+ 6
Example of default arguments for a function: int sum(int a = 5, int b = 10) { return a + b; } int main() { cout << sum(); } Even though we didn't pass any values when we called the function, we still get an output of 15, because a and b have a default value, declared by the = in the function parameters. If you did want to replace one of these values, you can easily do that by calling the function, and passing values in: sum(15); This will call the function, and set a to 15, and b is still 10 from its default value, because we didn't pass a second value in.
25th Aug 2016, 10:46 PM
Cohen Creber
Cohen Creber - avatar
0
i think argument is number whe give to function
25th Aug 2016, 9:41 PM
abolfazl
abolfazl - avatar