intintToAscii(intnumber){ return'0'+number;}main(){ printf("TheASCIIof5is%d\n",i"/> intintToAscii(intnumber){ return'0'+number;}main(){ printf("TheASCIIof5is%d\n",i">

Home  >  Article  >  Backend Development  >  Convert an integer to ASCII character in C/C++

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

王林
王林forward
2023-09-01 12:25:101667browse

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

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.

Example

#include<stdio.h>
int intToAscii(int number) {
   return &#39;0&#39; + number;
}
main() {
   printf("The ASCII of 5 is %d\n", intToAscii(5));
   printf("The ASCII of 8 is %d\n", intToAscii(8));
}

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete