+ 3
Why I'm not able to get output in float, But it's working for int.
#include<stdio.h> void* fun (const void* num); int main(){ float sqrts; float x = 5.2; sqrts = fun(&x); printf ("%f square is %f", x, sqrts); } void* fun (const void* num){ float result; result = (*(float*)num) * (*(float*)num); return result; }
3 Antworten
+ 1
Now, it works for float also :)
EDIT: @ lambor gopi, in your sixth line,
sqrts = fun(&x);
First thing, x is a float, so fun's parameter and return type should also be float.
Secondly,
result = (*(float*)num) * (*(float*)num);
type casting isn't required here, as *num is already a float type.
https://code.sololearn.com/cAftQ4HYwonp/?ref=app
0
Can u pls eloborate the reason why my program working for int and not working for float
this doubt araises while reading "functions using void pointers" in sololearn c
0
ok tnq. can u create one program like this using void pointer functions