ASCII Value of a Character

Program to find and display the ASCII value of a character

BeginnerTopic: Basic Programs
Back

C++ ASCII Value of a Character Program

This program helps you to learn the fundamental structure and syntax of C++ programming.

Try This Code
#include <iostream>
using namespace std;

int main() {
    char ch;
    
    cout << "Enter a character: ";
    cin >> ch;
    
    cout << "ASCII value of '" << ch << "' is: " << (int)ch << endl;
    
    return 0;
}
Output
Enter a character: A
ASCII value of 'A' is: 65

Understanding ASCII Value of a Character

Characters in C++ are stored as their ASCII (American Standard Code for Information Interchange) values. We can cast a char to int using (int) to get its ASCII value. Each character has a unique numeric value (A=65, a=97, etc.).

Note: To write and run C++ programs, you need to set up the local environment on your computer. Refer to the complete article Setting up C++ Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your C++ programs.

Table of Contents