what shall be the output of: (and why?)
printf("%d",2.37);
Apparently, printf is a variadic function and we can never 开发者_C百科know the type of a variable argument list. so we always have to specify the format specifiers manually. so, 2.37 would be stored as double according to IEEE standards would be fetched and printed in integer format. But the output is 0. What is the reason?
It is undefined behavior. You're passing a double
argument to a function that expects to retrieve an int
from its varargs macros, and there's no telling at all what that is going to lead to. In theory, it may even crash (with a calling convention that specifies that variadic arguments of different types are passed in different ways or on different stacks).
精彩评论