You pass a value int('a') for a format %fthat expects floator double. This behavior is undefined, which can lead to different results for each execution of the same program. The second printfhas the same problem: %fexpects floator double, but you pass the value int.
Here is the corrected version:
#include <stdio.h>
int main(void) {
int a = 50000;
float b = 'a';
printf("a = %d\n", a);
printf("b = %f\n", b);
printf("'a' = %d\n", 'a');
return 0;
}
Conclusion:
a = 50000
b = 97.000000
'a' = 97
, -Wall -W -Wextra . .
, clang :
clang -O2 -std=c11 -Weverything fmt.c -o fmt
fmt.c:8:24: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]
printf("b = %f\n", b);
~~~~~~ ^
1 warning generated.
b double printf(). double , float, , , .
double float , , API- , ...