Saturday, 1 June 2013

Giving a double type for sqrt library function in C

Giving a double type for sqrt library function in C

The C Programming Language by Ritchie says that "The library routine sqrt expects a double type and will produce nonsense if inadvertently handled something else.So if n is an integer,we can use sqrt((double) n) to convert the value of n to double."But the following code works fine on my system:
printf("%f",sqrt(9));
Then also it is giving the same result as sqrt((double)9).Why is my compiler not following the book?

No comments:

Post a Comment