在 C/C++ 中将 int 转换为 ASCII 字符
在 C 或 C++ 中,字符值存储为 ASCII 值。要将 int 转换为 ASCII,我们可以将字符'0'的 ASCII 值与整数相加。让我们举一个将 int 转换为 ASCII 值的示例。
示例
#include<stdio.h>
int intToAscii(int number) {
return '0' + number;
}
main() {
printf("The ASCII of 5 is %d\n", intToAscii(5));
printf("The ASCII of 8 is %d\n", intToAscii(8));
}
输出
The ASCII of 5 is 53 The ASCII of 8 is 56
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP