1 Answers
C++ functions can be assigned with default values. In absence of real arguments, default values will be considered Default values must be assigned from right to left, i.e. if one intermediate argument has a default value all subsequent elements also will have default values.
Example Code
int sum(int, int, int = 30); int main() { int a = 10, b = 20, c = 18; int r1, r2; r1 = sum(a, b, c); r2 = sum(a, b); // print r1,r2 return 0; } int sum(int x, int y, int z) { return x + y + z; }
Output:
48
60