#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.EOF
is of typeint
. You can only use%d
for anint
type variable.FWIW, if you want a floating point representation of an
int
, you have tocast
the variable (but I personally recommend to avoid this)