ใน C หรือ C ++ ค่าอักขระจะถูกเก็บไว้เป็นค่า ASCII ในการแปลงเป็น ASCII เราสามารถเพิ่ม ASCII ของอักขระ '0' ด้วยจำนวนเต็มได้ ให้เราดูตัวอย่างการแปลงค่าเป็น 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