# C 程序：查找字符的 ASCII 值

> 原文： [https://beginnersbook.com/2017/09/c-program-to-find-ascii-value-of-a-character/](https://beginnersbook.com/2017/09/c-program-to-find-ascii-value-of-a-character/)

ASCII 值将英文字符表示为数字，每个字母分配一个 0 到 127 之间的数字。例如，大写`Q`的 ASCII 值为 81。

## 示例 1：显示用户输入的字符的 ASCII 值的程序

该程序获取用户输入的字符并显示其 ASCII 值。

```c
#include <stdio.h>
int main()
{
    char ch;
    printf("Enter any character:");

    /* Reads the entered character and stores it
     * into the char variable ch
     */
    scanf("%c", &ch);

    /* Using the format specifiers we can get the ASCII code
     * of a character. When we use %d format specifier for a
     * char variable then it displays the ASCII value of a char
     */
    printf("ASCII value of character %c is: %d", ch, ch);
    return 0;
}
```

输出：

```c
Enter any character:Q
ASCII value of character Q is: 81
```

查看相关的 [C 程序](https://beginnersbook.com/2015/02/simple-c-programs/)：

1.  [C 程序：展示斐波那契序列](https://beginnersbook.com/2014/06/c-program-to-display-fibonacci-series/)
2.  [C 程序：检查数字是偶数还是奇数](https://beginnersbook.com/2015/02/c-program-to-check-if-number-is-even-or-odd/)
3.  [C 程序：计算并打印 nPr 的值](https://beginnersbook.com/2015/02/c-program-to-calculate-and-print-the-value-of-npr/)
4.  [C 程序：将大写字符串转换为小写](https://beginnersbook.com/2015/02/c-program-to-convert-uppercase-string-to-lowercase-string/)