Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Allows calling a function with fewer arguments by providing predefined values for parameters if the caller omits them.
void greet(string name, string msg = "Hello") {
cout << msg << ", " << name;
}
greet("Alice"); // Output: Hello, Alice
greet("Bob", "Welcome"); // Output: Welcome, BobDefault parameters must always be at the END of the parameter list. You cannot have a non-default parameter after a default one.
void error(int a = 1, int b); // ERROR!Default arguments can often replace the need for multiple overloaded functions, making the code more maintainable.