C++ Program to Print ASCII Value of All Characters in the String

This is a C++ Program to Display the ASCII Value of the Character Entered.

Problem Description

The program takes a character and prints its ASCII value. ASCII stands for American Standard Code for Information Interchange which is a numerical representation of characters in computers ranging from 0 to 127.

Problem Solution

1. A character is entered.
2. The equivalent ASCII value of the character is printed.
3. Exit.

C++ Program/Source code

Here is the source code of C++ Program to Display the ASCII Value of the Character Entered. The program output is shown below.

  1. #include<iostream>
  2. using namespace std;
  3. int main ()
  4. {
  5.     char c;
  6.     cout << "Enter a character : ";
  7.     cin >> c;
  8.     cout << "ASCII value of " << c <<" is :  " << (int)c;
  9.     return 0;
  10. }
Program Explanation

1. The user is asked to enter a character.
2. The ASCII value of the character which is the integer value is printed.

advertisement
advertisement
Runtime Test Cases
Case 1 :
Enter a character : M
ASCII value of M is : 77
 
Case 2 :
Enter a character : a
ASCII value of a is : 97
 
Case 3 :
Enter a character : S
ASCII value of S is : 83

Sanfoundry Global Education & Learning Series – C++ Programs.

To practice all C++ programs, here is complete set of 1000+ C++ Programming examples.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.