#include<stdio.h>
int main()
{
printf("%d",EOF);
}
generates -1 which is totally fine, but
#include<stdio.h>
int main()
{
printf("%f",EOF);
}
produces 0.000 . How can someone explain this when the expected output is -1.000?
#include<stdio.h>
int main()
{
printf("%d",EOF);
}
generates -1 which is totally fine, but
#include<stdio.h>
int main()
{
printf("%f",EOF);
}
produces 0.000 . How can someone explain this when the expected output is -1.000?
Using a wrong format specifier for any particular argument in
printf()invokes undefined behaviour.EOFis of typeint. You can only use%dfor aninttype variable.FWIW, if you want a floating point representation of an
int, you have tocastthe variable (but I personally recommend to avoid this)