Home > Back-end >  # define HGE '0.25' use printf % d output is 808333887
# define HGE '0.25' use printf % d output is 808333887

Time:11-23

Why is this result, write floating-point results is how to transform in character, I know that is wrong but the result is I want to know why?

CodePudding user response:

Printf (" % x \ n ", HGE); You will understand the

CodePudding user response:

The compiler to define this macro definition into a pointer, pointing to the temporary string, type is a pointer to the address

CodePudding user response:

refer to the second floor mzhan017 response:
compiler to define this macro definition into a pointer, pointing to the temporary string type is a pointer address

 
C: \ MinGW \ test> GCC printf. C
Printf. C: In the function 'main' :
Printf. C: blessing: warning: multi - character character constant [- Wmultichar]
16 | printf (" % d, % d ", legs, '0.26');
| ^ ~ ~
Printf. C: parts: warning: multi - character character constant [- Wmultichar]
16 | printf (" % d, % d ", legs, '0.26');
| ^ ~ ~ ~ ~ ~

CodePudding user response:

'0.25' is not a pointer, also is not a string, but int, on the small end architecture, memory layout is 35 30, 32 2 e x302e3235 is 0, 808333877 (808333887 should be the original poster write wrong)

CodePudding user response:

In front of me say a bit wrong, this should be with the size of the end it doesn't matter, the '0.25' is a literal, the left is the highest, most the right side is the lowest, so it is always 0 x302e3235 (808333877)

CodePudding user response:

Integer data in memory and floating-point representation method is different, so using % d output based on integer data to parse the floating point number, so that the results ~
  • Related