Program to print ASCII value of character

Program to print ASCII value of character

  • Write a program to print ascii value of character in C
  • Write a program to print ascii value of character in C++
  • Write a program to print ascii value of character in Python
  • Write a program to print ascii value of character in PHP
  • Write a program to print ascii value of character in Java
  • Write a program to print ascii value of character in Java Script
  • Write a program to print ascii value of character in C#

Explanation:

In the ASCII table, a character’s ASCII (American Standard Code for Information Interchange) value is its numerical equivalent. For normal ASCII, each character is given a distinct integer value between 0 and 127.

  • ASCII values represent characters like:
    • Letters: ‘A’ = 65, ‘a’ = 97
    • Digits: ‘0’ = 48, ‘1’ = 49
    • Symbols: ‘@’ = 64, ‘#’ = 35
    • Control Characters: Newline (\n), Tab (\t), etc.
    • Extended ASCII (0–255) includes additional characters used in some encodings.

Program to print ascii value of character

#include <stdio.h>

int main() {
    char ch = 'A';
    printf("The ASCII value of '%c' is %d\n", ch, ch);
    return 0;
}

#include <iostream>

int main() {
    char ch = 'A';
    std::cout << "The ASCII value of '" << ch << "' is " << int(ch) << std::endl;
    return 0;
}

ch = 'A'
print(f"The ASCII value of '{ch}' is {ord(ch)}")

<?php
$ch = 'A';
echo "The ASCII value of '$ch' is " . ord($ch) . "\n";
?>

public class Main {
    public static void main(String[] args) {
        char ch = 'A';
        System.out.println("The ASCII value of '" + ch + "' is " + (int) ch);
    }
}

let ch = 'A';
console.log(`The ASCII value of '${ch}' is ${ch.charCodeAt(0)}`);

using System;

class Program {
    static void Main() {
        char ch = 'A';
        Console.WriteLine($"The ASCII value of '{ch}' is {(int)ch}");
    }
}

List of All Programs