C 语言中 printf 语句的换行符 '\n' 解释
如果在上述示例中不在printf语句中加入\n,则两行文本将会连续输出而不换行,如下所示:
#include <stdio.h>
int main() {
printf("Hello, World!");
printf("This is a new line.");
return 0;
}
运行该程序后,输出将会是以下内容:
Hello, World!This is a new line.
可以看到,两个printf语句的输出内容没有换行,而是连续输出到同一行。如果希望在输出中创建新的行,需要在所需的位置使用\n转义序列来插入换行符。
原文地址: https://www.cveoy.top/t/topic/iY6 著作权归作者所有。请勿转载和采集!