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

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