printf("格式化字符串", 变量1, 变量2, ...);要使用 printf() 函数进行换行输出,可以使用换行符转义序列">

c语言程序怎么换行输出

来源:这里教程网 时间:2026-02-21 16:46:18 作者:

如何使用 C 语言程序换行输出

在 C 语言中,换行输出可以实现文本行尾的换行,即创建新的一行。有两种常用的方法可以实现换行输出:

    printf() 函数

    printf()
    函数的格式为:

    立即学习“C语言免费学习笔记(深入)”;

    <code class="c">printf("格式化字符串", 变量1, 变量2, ...);</code>

    要使用

    printf()
    函数进行换行输出,可以使用换行符转义序列
    \n

    <code class="c">printf("换行输出\n"); // 输出 "换行输出" 并换行</code>

    putchar() 函数

    putchar()
    函数将单个字符输出到标准输出中。要实现换行输出,可以使用换行符 ASCII 码 10:

    <code class="c">putchar(10); // 换行输出</code>

用法演示

以下代码段演示了这两种换行输出方法:

<code class="c">#include <stdio.h>
int main() {
    // 使用 printf() 函数换行输出
    printf("换行输出 1\n");
    // 使用 putchar() 函数换行输出
    putchar(10);
    printf("换行输出 2");
    return 0;
}</code>

输出结果:

<code>换行输出 1
换行输出 2</code>

相关推荐