Casting not working well in C -
programming c using xcode, here's f
#include <stdio.h> int multiply (int x, int y) { return x * y; } int main() { float result = (float) multiply (0.2, 0.5); printf("the result %f", result); }
i don't right value, 0.0000 !! did casting don't know whats wrong.
your program multiplies 0
0
.
multiply
takes 2 int
parameters, 0.2
, 0.5
implicitly converted int
before making call. truncates both 0
.
your typecast doesn't anything in program, since return value of multiply
(which int
) implicitly converted during assignment result
anyway.
you need change definition of multiply
(or add floating-point version , call that) if want program work correctly.
Comments
Post a Comment