Why does the result of printf number change when include tab?

时间:2019-04-17 02:03:37

标签: c printf

The below code show wrong result for 44 and 84.

enter image description here

So, I tried to change \t into space and the numbers were shown correctly as shown below.

enter image description here

Why just having tab in printf cause the number to be print incorrectly? I have tried to change 4 into 7 and 8 and the same problem occurred.

#include <stdio.h>

int main()
{
    for (int count = 1; count <= 100 ; ++count)
    {
        if((count % 4) == 0 )
            printf("%d\t", count);
    }

    return 0;
}


and

#include <stdio.h>

int main()
{
    for (int count = 1; count <= 100 ; ++count)
    {
        if((count % 4) == 0 )
            printf("%d ", count);
    }

    return 0;
}


2 个答案:

答案 0 :(得分:2)

It is printing correctly, but because of the online compiler cutting off the first digit (for some reason) you are unable to see it. If you click the 3rd button above the output screen (which will copy the output) and paste it into notepad you will see that your output is correct.

答案 1 :(得分:1)

Indeed. It is the out steam that cuts off the first character of the next line