Open In App

Program to print ASCII Value of a character

Last Updated : 13 Oct, 2025
Comments
Improve
Suggest changes
63 Likes
Like
Report

ASCII (American Standard Code for Information Interchange) assigns a numerical value to each character. In programming, we often need to get the ASCII value of a character.

Examples:

Input:
Output: 97

Input: D
Output: 68

Explanation: The ASCII values of 'a' and 'D' are 97 and 68 respectively.

Below are few methods in different programming languages to print ASCII value of a given character : 

In Python

Python provides the built-in ord() function to get the ASCII value of a character.

Python
c = 'g'
print(ord(c))

Output
103

In C

In C, the %d format specifier can be used to print the ASCII value of a character:

CPP
#include <stdio.h>
int main() {
    char c = 'k';
    printf("%d",c);
    return 0;
}

Output
107

In C++

In C++, we can use the int() function to convert a character to its ASCII value:

C++
#include <iostream>
using namespace std;

int main() {
    char c = 'A';
    cout <<int(c);
    return 0;
}

Output
65

In Java

In Java, assigning a char to an int variable gives its ASCII value:

Java
public class AsciiValue {
    public static void main(String[] args) {
        char c = 'e';
        int ascii = c;
        System.out.println(ascii);
    }
}

Output
101

In C#

The concept to print ascii in c# is similar to that of Java:

C#
using System;

public class AsciiValue {
    public static void Main() {
        char c = 'e';
        int ascii = c;
        Console.WriteLine(ascii);
    }
}

Output
101

In JavaScript

JavaScript provides the charCodeAt() method to get ASCII value:

JavaScript
val = 'A'
console.log(val.charCodeAt(0));

Output
65

C++ Program to Find ASCII value of a Character
Video Thumbnail

C++ Program to Find ASCII value of a Character

Video Thumbnail

Python Program to print ASCII Value of a Character

Explore