Convert an int to ASCII character in C/C++

CC++Server Side ProgrammingProgramming

In C or C++ the character values are stored as ASCII values. To convert int to ASCII we can add the ASCII of character ‘0’ with the integer. Let us see an example to convert int to ASCII values.


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
Updated on 30-Jul-2019 22:30:26