下面的代码显示 44 和 84 的错误结果。
因此,我尝试将\t 更改为空格,并且数字正确显示,如下所示。
为什么 printf 中只包含制表符会导致数字打印不正确? 我尝试将4改为7和8,也出现了同样的问题。
#include <stdio.h>
int main()
{
for (int count = 1; count <= 100 ; ++count)
{
if((count % 4) == 0 )
printf("%d\t", count);
}
return 0;
}
和
#include <stdio.h>
int main()
{
for (int count = 1; count <= 100 ; ++count)
{
if((count % 4) == 0 )
printf("%d ", count);
}
return 0;
}
最佳答案
它打印正确,但由于在线编译器切断了第一个数字(由于某种原因),您无法看到它。如果您单击输出屏幕上方的第三个按钮(这将复制输出)并将其粘贴到记事本中,您将看到您的输出是正确的。
关于c - 为什么包含 tab 时 printf 数字的结果会改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55718881/