Back to questions
JuniorTheoryCommon
What happens when this program is compiled and run?
func double(n: Int) -> Int {
n * 2
}
print(double(4), terminator: " ")
print(double(n: 3))It does not compile
- Expecting
8 6: treating a label as optional when there is one argument. A parameter declared without_needs its label in every call, sodouble(4)does not compile. - Expecting the error only when the program reaches
double(4). Labels are checked by the compiler before the program runs, so nothing is printed at all.
- How would you change the declaration so that
double(4)compiles? - What error does
double(n: 3)give if the parameter is declared as_ n?