could anyone give me a short explanation?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

could anyone give me a short explanation??

is it possible for a function of type 'int' have parameters of another type like 'float'...? int func(float a,float b) or the parameters data type must be same as the function's ???

30th Apr 2018, 7:20 AM
RiGeL
RiGeL - avatar
3 Answers
+ 7
Do you mean a function that returns an int that has float parameters? Yes, because these parts are separate & play different roles. There are four parts making up a function definition. Using the example you gave the int is the return type, func is the name and the floats a & b are parameters. When we call the function we must provide these two floats in order for the call to work, then depending on the statements in the body (not shown) it will return a value of type int. Not that short, but I hope it helps ☺
30th Apr 2018, 8:39 PM
G.T.T
G.T.T - avatar
+ 2
Nope thats fine, the return type has to be an int though
30th Apr 2018, 7:22 AM
TurtleShell
TurtleShell - avatar
+ 1
if you will try to return float, the Compiler will cast it to int, so it's fine.
30th Apr 2018, 7:41 AM
Cain Eviatar
Cain Eviatar - avatar