Labs ICT
Pro Login

Default Arguments

Default Arguments

You can give parameters a default value. If the caller doesn't provide that argument, the default kicks in.

int multiply(int a, int b = 1) {
  return a * b;
}

int main() {
  cout << multiply(5, 3);
  cout << multiply(5);
  return 0;
}

Default arguments must go after all required parameters. You can't skip an argument — either provide it or rely on the default.

This feature reduces overloaded functions and makes calling code simpler when most calls use a common value.

void log(string message, string prefix = "INFO") {
  cout << "[" << prefix << "] " << message;
}
Try it Yourself →