+ 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 ???
3 ответов
+ 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 ☺
+ 2
Nope thats fine, the return type has to be an int though
+ 1
if you will try to return float, the Compiler will cast it to int, so it's fine.