+ 4
Which function will be called in function overloading double/float?
If you declare two fuctions sum(double x,double y) and sum(float x,float y) to sum two values which fuction will be called through function overloading when you input two decimal values(ex. 12.6,4.5) Do upvote guys❤
7 ответов
+ 1
double is your default floatingpoint datatype, and integer is your default number datatype.
if you write
float a = 12.4;
the compiler actually casts the 12.4 from double to float.
if you write:
long a = 1034;
the compiler casts the 1034 from int to long.
(byte and short are treated as integers internally anyways)
oh and: all this is java based.
+ 3
That can be taken eithet as float or double value.so what now??
+ 3
nope, those are doubles. if you want them to be float you would have to write 12.6F and 4.5F
+ 3
so is double the default data type for decimal values? Cause even to specify it is double i have to mention it as 12.6d &4.5d
It is only possible if double is taken as default.
+ 3
@jeremy
Is it the same way in c/cpp?
+ 2
you are passing double values, therefore the method with the double parameters is used.
+ 1
im not 100% sure but i think so. i just tried to store 12.4 in a float in c# and i received and error that you cant store a double in a float.
No idea about cpp, you have to try it i guess.