重复输出的类型是怎么回事,它如何区分迭代次数和 Ascii 代码?

What's with the sort of repetitive output and how does it differentiate between the number of iterations and the Ascii code?

本文关键字:迭代 代码 Ascii 何区 输出 类型 怎么回事      更新时间:2023-10-16

运行以下代码并输入A后,这是我的输出:

char   0 is character A with ascii code 65
char   1 is character 
 with ascii code 10

我有两个问题:

  1. 为什么输出

    char 0 is character A with ascii code 65
    

    而不是

    char 65 is character A with ascii code 0
    

该程序如何知道第一个"%3D"与迭代次数(我认为(和第二个"%d"与ASCII值相关联?"%c"是一种字符数据类型,因此它打印a,但是除了第一个"%3D"之前的3个,"%d"之间没有区别位置包括小数点?

  1. 在哪里

    char 1 is character 
     with ascii code 10
    

来自?它与代码中的c,c部分有关吗?

#include <stdio.h>
main ()
{
    int c,n=0;
    while ((c=getchar()) !='Q' )
    printf ("char %3d is character %c with ascii code %dn", n++, c,c);
}

格式指定符的顺序与printf的参数相同,因此"%3D"对应于printf的第二个参数,%c与第三个参数相对应,而"%d"对应于第四。通常, printf的n 1个参数对应于nth格式。

在呼叫printf("cahr %3d is character %c with ascii code %dn", n++, c, c)中,"%3D"对应于参数n++,%c"对应于c,而"%D"对应于第二个c

的原因
char 1 is character 
 with ascii code 10

行是在按Enter键时输入newline字符。