c - 为什么包含 tab 时 printf 数字的结果会改变?

标签 c printf

下面的代码显示 44 和 84 的错误结果。

enter image description here

因此,我尝试将\t 更改为空格,并且数字正确显示,如下所示。

enter image description here

为什么 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/

相关文章:

编译器优化返回值?

c - 使用 fgets 刷新缓冲区

c - 当一个字符传递给 printf 函数时,如何将其提升为 int?

c - 从 C 中的二进制文件中读取

c - 如何在C中打印未指定大小的数组

c - 为什么这样一个结构体包含两个只包含一个元素的数组字段?

c - 如何扫描数据文件并在数字首次超过设定数字时将值打印到屏幕

java - 为什么我们不能在java中的printf中使用整数精度?只是好奇

c - printf 和 scanf 的逻辑问题

c - 如何在C中将数字矩阵打印成字符串?