int area(int side) { return side * side; }
double area(double r) { return 3.14159 * r * r; }
int area(int w, int h) { return w * h; }
cout << area(4); // 16 (int)
cout << area(2.0); // 12.56 (double)
cout << area(3, 5); // 15 (two ints)
Parameters with defaults are optional at call sites:
string greet(string name, string prefix = "Hello") {
return prefix + ", " + name + "!";
}
greet("Alice"); // "Hello, Alice!"
greet("Alice", "Hi"); // "Hi, Alice!"
Default parameters must come last in the list.
Write repeat(string s, int times = 2) that concatenates s exactly times times.
Example: repeat("ha", 3) → "hahaha" repeat("ab") → "abab"
Click "Run" to execute your code.