1

The following code is simple. As expected, it should print 100, 100.

#include <stdio.h>
#include <math.h>

int main(int argc, char const *argv[])
{
    int a = 10, b, c;
    b = pow(10, 2);
    c = pow(a, 2);
    printf("%d, %d\n", b, c);
    return 0;
}

On OS X 10.10, clang, the result is as expected. On Windows 10, gcc, the result is however 100, 99.

screenshot

What is the cause of it?

Colliot
  • 1,522
  • 3
  • 16
  • 29
  • Another duplicate: http://stackoverflow.com/q/19126809/1009479 – Yu Hao Jun 13 '15 at 11:35
  • At least OP tried with 2 different compilers, so it's noteworthy one of them *happened* to give the right answer and the other one did not. (For these two numbers *only*. It's not as if clang will *always* get it right. Even when it does, it's only their implementation, rather than some fault in gcc.) – Jongware Jun 13 '15 at 11:40
  • In codeblocks version 10 on Ubuntu, your code giving me correct result. –  Jun 13 '15 at 12:17

0 Answers0