I've encountered this strange phenomenon that my "Math.pow" function works wrongly if parameters are given as variable. So note that
int result = pow(2,4);
works just fine. But the following code does not:
int main()
{
int base = 2;
int p = 4;
int result = pow(base,p);
printf("%i\n" , result);
}
int pow(int base, int pow){
int result = 1;
for(int i = 0; i < pow; i++){
result = result * base;
}
return result;
}
Strangely, placing the pow function above main method just solves the problem. Why does this happen?