# 数据输出函数

在C语言中，有三个函数可以用来在显示器上输出数据：

* puts()：只能输出字符串，
* putchar()：只能输出单个字符，本节将会介绍。
* printf()：可以输出各种类型的数据，并且可以进行格式化输出。

printf() 是最灵活、最复杂、最常用的输出函数，完全可以替代 puts() 和 putchar()，一定要掌握。

## putchar()

putchar() 函数只能用来输出单个字符，例如：

```c
#include <stdio.h>
#include <stdlib.h>
int main()
{
    putchar('a');
    putchar(7);
    putchar('\x46');

    system("pause");
    return 0;
}
```

运行程序，输出 aF，同时会听到喇叭发出“嘟”的声音。

## 关于换行

puts() 函数在输出结束时会自动换行，而 printf() 和 putchar() 不会，需要手动添加换行符`\n`。如下所示：

```c
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char *str = "ccc";
    int n = 100;
    char c = 'Z';
    puts(str);
    putchar(c);
    printf("%d", n);
    putchar(c);

    system("pause");
    return 0;
}
```

运行结果：

```
c.biancheng.net
Z100Z请按任意键继续. . .
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/c/shu-ru-shu-chu/shu-ju-shu-chu-han-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
