Kindly explain with all code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Kindly explain with all code

the effect of a default argument can be alternativly achieved by overloading discuss with an example

24th Dec 2020, 8:31 PM
Pranay Sehgal
Pranay Sehgal - avatar
3 Answers
+ 2
You can leave out arguments with default value. And you can alternatively create overloads with and without that argument. int plusTwo(int n=0){return n+2;} ---or--- int plusTwo(int n){return n+2;} int plusTwo(){return plusTwo(0);} In both cases you can call with or without argument: plusTwo() returns 2 plusTwo(0) returns 2
24th Dec 2020, 11:45 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 1
Which code, what language? To whom explain?
24th Dec 2020, 9:02 PM
Shadoff
Shadoff - avatar
0
Please tag a relevant language name to clarify context. You are taking multiple classes it is not possible to deduce language context without one specified in the tags ☝ Some programming languages does not support default argument in functions e.g. Java.
25th Dec 2020, 12:40 AM
Ipang