重复输出的类型是怎么回事,它如何区分迭代次数和 Ascii 代码?
What's with the sort of repetitive output and how does it differentiate between the number of iterations and the Ascii code?
运行以下代码并输入A后,这是我的输出:
char 0 is character A with ascii code 65
char 1 is character
with ascii code 10
我有两个问题:
为什么输出
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"之间没有区别位置包括小数点?
在哪里
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字符。
相关文章:
- 为什么此代码的矢量迭代器没有停止?
- 我的代码在作为参数传入 .begin() 时不起作用,但在我将 .begin() 转换为迭代器后工作
- 如果我在下面的代码中使用 list 而不是 vector,为什么在我尝试在迭代器之间执行减法的行中编译失败?
- 在每次循环迭代时停止代码执行毫秒
- 在下面的 C++ 代码中,*(迭代器)和 *(++迭代器)是什么意思?
- 为什么在此代码中隐式转换为常量迭代器失败?
- 我通过迭代加法将二进制数转换为十进制并检查单个字符(请参阅代码)的方法有什么问题?
- 在此C++代码中,迭代器引用列表的哪个元素?
- 让宏将迭代参数传递到通过宏变量提供的代码体中
- 迭代列表以查找元素的出现.代码问题
- 重复输出的类型是怎么回事,它如何区分迭代次数和 Ascii 代码?
- 循环在此代码中仅迭代一次,而在另一个代码中正确迭代
- 如何使用迭代器显示以下代码的输出
- 如何调整我的代码以确保我的迭代代码接受用户输入
- 不使用循环如何迭代代码指令
- 在 OpenGL 中绘制立方体。迭代代码较短,但不起作用
- 段树的迭代代码
- ICU迭代代码点
- C++向量迭代代码无法编译,当向量作为对常量的引用传递时
- 使用模拟测试迭代代码——它有意义吗?