Computer >> 컴퓨터 >  >> 프로그램 작성 >> C 프로그래밍

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