Here is what can happen here. You should be able to confirm this by looking at the implementation of your pow function compiler:
Assuming you have the correct #include, (all the previous answers and comments about this are correct - do not accept #include files as given), the prototype of the standard pow function is the following:
double pow(double, double);
and you call pow like this:
pow(5,2);
The pow function goes through an algorithm (possibly using logarithms), so it uses functions and floating-point values ββto calculate the power value.
The pow function does not go through the naive "multiply the value of x by the sum of n times", since it must also calculate pow using fractional exponents, and you cannot calculate fractional powers in this way.
Thus, it is more likely that the calculation of pow using parameters 5 and 2 led to a small rounding error. When you assigned int , you truncated the fractional value, giving 24.
If you use integers, you can write your own "intpow" or similar function, which simply multiplies the value as many times as necessary. The advantages of this:
PaulMcKenzie Sep 05 '14 at 4:42
source share