I can't explain the behaviour of the following program (compiled with gcc on mingw 32 bits). I'm aware of the possible precision loss when implicitly converting from double to int, but I would expect the two cases to give the same output since it is doing the exact same operations. Why are the two outputs different?
#include <stdio.h>
#include <math.h>
int main()
{
int table[3] = {2, 3, 4};
int i, N;
N = 0;
N += table[0] * pow(100, 0);
N += table[1] * pow(100, 1);
N += table[2] * pow(100, 2);
printf("%d\n", N);
N = 0;
for(i = 0; i < 3; i++)
N += table[i] * pow(100, i);
printf("%d\n", N);
return 0;
}
//output:
40302
40300