I use codeblock for compilation.
code:
int main(){
int l=pow(10,2);
cout<<l;
return 0;
}
OUTPUT-99
int main(){
int l=pow(10,3);
cout<<l;
return 0;
}
OUTPUT-1000
I use codeblock for compilation.
code:
int main(){
int l=pow(10,2);
cout<<l;
return 0;
}
OUTPUT-99
int main(){
int l=pow(10,3);
cout<<l;
return 0;
}
OUTPUT-1000
In short - because of integer truncation.
The function pow
operates on two floating-point values and returns a floating-point value. When working on integers, the result of pow(10,2)
might be stored as 99.9999999, or 100.0000000001. Due to integer truncation, 99.9999999 gets truncated down to 99, and 100.0000000001 gets truncated down to 100.
Same goes for pow(10,3)
, with 999.9999999, or 1000.0000000001 - which will be truncated to 999 or 1000.
You can read more about the pow function here.