在 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