Reputation: 477
What's the problem with this code ?
printf("%d", pow(2, 10));
as format specifier used is integral , it should give an integer value . But it don't . Why so ?
output - 0
Expected output - 1024
Upvotes: 0
Views: 73
Reputation: 106012
pow
return double
. You are using wrong specifier to print a double
value. This will invoke undefined behavior and you may get either expected or unexpected result. Use %f
instead.
printf("%f", pow(2, 10));
Upvotes: 5
Reputation: 141574
The pow
function from <math.h>
returns type double
.
The format specifier for double
is %f
. You used the wrong specifier, so your program causes undefined behaviour. Literally anything could happen.
To fix this, use %f
instead.
BTW if you want to compute 2
to the power 10
in integers you can write 1 << 10
.
Upvotes: 4