strange output while printing float as integer and integer as float in C [duplicate]
问题 This question already has an answer here : Why are the int and float passed in printf going to the wrong positions in the format string? (1 answer) Closed 2 days ago . the following code is not showing the expected output which is garbage value ( strangely the values are swapped ) #include<stdio.h> int main() { float f = 4.6; int d = 7; printf("%d %f\n",f,d); return 0; } output: 7 4.600000 回答1: Let's reduce this a bit: float f = 4.6; printf("%d\n", f); That's undefined behavior . The correct