In this article, you’ll learn how to find the ASCII value of a character using C++, Python, JavaScript, and C.
Problem Statement
You’re given a character and you need to print the ASCII value of that character.
Example 1: Let the given character be ‘M’.
The ASCII value of ‘M’ is 77.
Thus, the output is 77.
Example 2: Let the given character be ‘U’.
The ASCII value of ‘U’ is 85.
Thus, the output is 85.
Example 3: Let the given character be ‘O’.
The ASCII value of ‘O’ is 79.
Thus, the output is 79.
If you want to have a look at the complete ASCII table, you can check out asciitable’s website.
C++ Program to Find the ASCII Value of a Character
You can find the ASCII value of a character using int() in C++. Below is the C++ program to print the ASCII value of a character:
Output:
Python Program to Find the ASCII Value of a Character
You can find the ASCII value of a character using ord() in Python. Below is the Python program to print the ASCII value of a character:
Output:
JavaScript Program to Find the ASCII Value of a Character
You can find the ASCII value of a character using string.charCodeAt(0) in JavaScript. Below is the JavaScript program to print the ASCII value of a character:
Output:
C Program to Find the ASCII Value of a Character
You can find the ASCII value of a character using format specifiers in C. Below is the C program to print the ASCII value of a character:
Output:
Build Your Programming Skills in Fun, Practical Ways
Programming is fun once you get better at it and know what you’re doing. You can learn programming in a number of ways. But the hands-on method of learning programming can help you learn faster and retain the info for a longer period of time.
Building Coding Games is one of the best methods to get hands-on experience while having fun at the same time.