int main()
{
int a=5;
float b=7.5;
printf(\"%d %f\\n\",a,b);
printf(\"%d %f\\n\",a,a);
return 0;
}
when i compile this in gcc
printf prototype is:
int printf(const char *format, ...);
The ellipsis notation in a function prototype declarator causes argument type conversion to stop after the last declared parameter. The default argument promotions are performed on trailing arguments.
the integer promotions are performed on each argument, and arguments that have type float are promoted to double. These are called the default argument promotions.
Therefore, no other argument promotion is performed with a printf call. In particular, a is not converted to double. Hence it will result in a undefined behavior: printf will try to get a double with a given size (sizeof(double)) and a given memory representation, which could be different from an int.
fprintf functionIf a conversion specification is invalid, the behavior is undefined. If any argument is not the correct type for the corresponding conversion specification, the behavior is undefined.
Besides, you can look at the ASM code generated by gcc to see what is going on.