Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What happens when the output result of pow (10,2) is expressed as 0 by integer and 100.0 by floating point number?
What happens when the output result of pow (10,2) is expressed as 0 by integer and 100.0 by floating point number?
It's not the compiler. The return value type of Pow () is double. Using "%d" for double precision/floating point data output format will get strange values.

To avoid this, you can add a type conversion:

printf("%d ",pow( 10,2))-& gt; The output is 0

printf("%d ",(int)pow( 10,2))-& gt; The output is 100

This is related to the parameters of va_start/va_arg/va_end analysis variables. When printf encounters "%d", it uses int* type to get variables from the parameter list, while float/double is 8 bytes, so it only gets half -4 bytes.

See how floating point 100 is stored in memory:

00 00 00 00 59 40—Storage of floating point 100 in memory (16 hexadecimal, 8 bytes).

Take 4 bytes with int pointer and get 0.

And if we use cast to convert floating point into int, we can get the correct 100.