int a=5;
float b=3.5;
printf(\"%d\",b);
printf(\"\\n%f\",a);
Can anyone please tell me why this code is showing unexpected output (garbage\\n3.5)>
int main()
{
int a=5;
float b=3.5;
printf("%f",b); //Use %f
printf("\n%d",a); // Use %d
}
Refer: printf
wrong format specifier to printf leads undefined behavior in most cases.
However, since printf is a variadic function, and the arguments to variadic
functions undergo the default argument cast.
Like, a char is casted to an int.