What happens if a caller passes too many parameters to a function and if a caller passes too few parameters to a function ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What happens if a caller passes too many parameters to a function and if a caller passes too few parameters to a function ?

24th Dec 2018, 6:07 PM
Pradeep Kumar
Pradeep Kumar - avatar
4 Answers
+ 3
function won't work if you pass less or more than required arguments to it
24th Dec 2018, 6:15 PM
Mayank Dhillon
Mayank Dhillon - avatar
+ 2
compile error
24th Dec 2018, 6:27 PM
Asirap
+ 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.
24th Dec 2018, 6:37 PM
Alquen
Alquen - avatar
+ 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.
24th Dec 2018, 7:47 PM
HonFu
HonFu - avatar