+ 1
What happens if a caller passes too many parameters to a function and if a caller passes too few parameters to a function ?
4 ответов
+ 3
function won't work if you pass less or more than required arguments to it
+ 2
compile error
+ 2
It depends on the language. In C++, passing too few or too many arguments will result to an error. Unlike in JavaScript, passing few arguments will make other arguments without value undefined. Passing many arguments will have no effect to the function, as long as the parameters are filled in.
+ 2
It can also depend on how the function is designed. (Examples in Python.)
def f(a, b=0):
...
if you call this with only one argument, it will still be ok, because b is pre-defined as 0.
def f(*c):
...
Here you can pass as many arguments as you want, they will all be crammed into the tuple c.