I am using Dev C++ 4.9.9.2 with default compiler as provided in Dev C++ options. Consider the following two programs:
First:
#include <iostream>
#include <math.h>
using namespace std;
int main (){
cout <<(int)pow (10,2); //100
return 0;
}
Second:
#include <iostream>
#include <math.h>
using namespace std;
int main (){
int k = 2;
cout <<(int)pow (10,k); //99
return 0;
}
Is that a bug in implicit coercion from int
to datatype of arument of called pow
in the compiler shipped with Dev C++ 4.9.9.2? OR is that an expected behaviour? Exactly which version of pow
is called (I tried to debug but was unable to locate called one)?
Note : If we replace math.h by cmath, the program does not compile with a warning of ambiguous call to pow (seems a better condition). Also on newer version of Dev C++ on the same system, the output is correct in both programs.
Edit1 : I don't think that my question is duplicate of this question as I am giving same input but getting different result. 2 and k both are integers.
Edit2 : I feel that people are less interested in understanding my question than seeing my rep. That's why they marked the question as a duplicate. They don't bother that I am giving the same inputs in different ways but getting different results.