< Previous | Contents | Next >

Overriding Default Arguments

Next I call askNumber() again with:

number = askNumber(10, 5);

This time I pass a value for low5. This is perfectly fine; you can pass an argument for any parameter with a default argument, and the value you pass will override the default. In this case, it means that low is assigned 5.

As a result, the user is prompted for a number between 5 and 10. Once the user enters a valid number, askNumber() returns that value and ends. Back in main(), the value is assigned to number and displayed.