In C or C, character values are stored as ASCII values. To convert an int to ASCII, we add the ASCII value of the character "0" to the integer. Let's look at an example of converting an int to an ASCII value.
#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
The above is the detailed content of Convert an integer to ASCII character in C/C++. For more information, please follow other related articles on the PHP Chinese website!