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

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

王林
Release: 2023-09-01 12:25:10
forward
1770 people have browsed it

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));
}
Copy after login

Output

The ASCII of 5 is 53
The ASCII of 8 is 56
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template