Answer the question
In order to leave comments, you need to log in
Why is (int) pow ( variable1, variable2 ) cast different from (int) pow ( constant1, constant2 )?
#include <stdio.h>
#include <math.h>
int main() {
int base = 10;
int k = 2;
printf("%d\n", (int) pow(base, k) );//99
printf("%d\n", (int) pow(base, 2) );//99
printf("%d\n", (int) pow(10, k) );//99
printf("%d\n", (int) pow(10, 2) );//100
return 0;
}
Answer the question
In order to leave comments, you need to log in
In the latter case, apparently, some kind of compiler optimization played and there was no real call to pow.
In general, 99 is obtained as a result of converting a floating point to an int.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question