void main()
{
clrscr();
float f = 3.3;
/* In printf() I intentionaly put %d format specifier to see
what type of output I may get */
printf("value of variable a is: %d", f);
getch();
}
最佳答案
实际上,%d
告诉printf
在某个位置查找整数参数。但是您传递了float
参数,该参数放置在其他位置。 C标准未指定执行此操作时将发生的情况。在这种情况下,printf
寻找整数参数的位置可能为零,因此它显示为“ 0”。在其他情况下,可能会发生不同的事情。
关于c - 为什么此代码打印为0?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51861023/