There is something I don't understand about casting. This works if I put a double in the place of (float)n.

Code:`#include <math.h>`

...

int n = 10;

....

printf("%f\n", sqrt((float)n));

Printable View

- 12-23-2009RogerProblem with sqrt and cast
There is something I don't understand about casting. This works if I put a double in the place of (float)n.

Code:`#include <math.h>`

...

int n = 10;

....

printf("%f\n", sqrt((float)n));

- 12-23-2009bithub
What's your question? double and float are both floating point types, the difference is that double has more precision.

sqrt() takes a double type as the parameter. If you give it a int or a float, it will be implicitly converted to a double, so the cast is actually unnecessary.