English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structures

C Language Files

C Others

C Language Reference Manual

C program to find the ASCII value of a character

Comprehensive Collection of C Programming Examples

In this example, you will learn how to find the ASCII value of a character.

In C programming, character variables store ASCII values (0 to127integer between them) rather than the character itself. This value is called ASCII value.

For example, the ASCII value of 'A' is65.

This means, if you assign a character variable 'A',65It will be stored in the variable rather than 'A' itself.

Now, let's see how to print the ASCII value of a character in C programming.

The program prints the ASCII value

#include <stdio.h>
int main() {  
    char c;
    printf("Enter a character: ");
    scanf("%c", &c);  
    
    //%d displays the integer value of the character
    //%c displays the actual character
    printf("%c's ASCII value = %d", c, c);
    
    return 0;
}

Output Result

Enter a character: G
The ASCII value of G = 71

In this program, the user is required to enter a character. The character is stored in the variable c.

When using the %d format string, it will display71(ASCII value of G).

When using the %c format string, 'G' itself will be displayed.

Comprehensive Collection of C Programming Examples