ASCII value in C

In the C programming language, you can obtain the ASCII value of a character by using the type casting or implicit conversion. The ASCII value represents the numeric code of a character in the ASCII character set.

Here’s an example that demonstrates how to obtain the ASCII value of a character in C:

#include <stdio.h>

int main() {
    char ch = 'A';
    int asciiValue = (int)ch;

    printf("The ASCII value of '%c' is %d\n", ch, asciiValue);

    return 0;

In this example, the character 'A' is assigned to the variable ch. By explicitly casting ch to an int using (int)ch, we obtain the ASCII value of the character. The resulting ASCII value is stored in the variable asciiValue.

The printf statement is then used to display the character and its corresponding ASCII value.

When you run this program, the output will be:

The ASCII value of ‘A’ is 65

The ASCII value of 'A' is 65

Note that in C, characters are represented using single quotes (').

What is ASCII code?

ASCII (American Standard Code for Information Interchange) is a character encoding standard that assigns unique numeric codes to represent characters. It is a widely used character encoding scheme that provides a standard way to represent text in computers and other electronic devices.

The ASCII character set consists of 128 characters, including control characters (such as line feed, carriage return, and tab) as well as printable characters (such as letters, digits, punctuation marks, and special symbols). Each character is assigned a unique numeric value ranging from 0 to 127.

Here are some common ASCII values and their corresponding characters:

  • ASCII value 65 represents the uppercase letter ‘A’.
  • ASCII value 97 represents the lowercase letter ‘a’.
  • ASCII value 48 represents the digit ‘0’.
  • ASCII value 32 represents the space character.
  • ASCII value 33 represents the exclamation mark ‘!’.
  • ASCII value 126 represents the tilde character ‘~’.

The ASCII encoding scheme has been widely used in computer systems, communication protocols, and programming languages. However, it only supports a limited character set and does not include characters from non-English languages. As a result, different character encoding schemes, such as Unicode, have been developed to support a broader range of characters and scripts.