ASCII Value in C

The full form of ASCII is the American Standard Code for information interchange. It is a character encoding scheme used for electronics communication. Each character or a special character is represented by some ASCII code, and each ascii code occupies 7 bits in memory.
In C programming language, a character variable does not contain a character value itself rather the ascii value of the character variable. The ascii value represents the character variable in numbers, and each character variable is assigned with some number range from 0 to 127. For example, the ascii value of 'A' is 65.
In the above example, we assign 'A' to the character variable whose ascii value is 65, so 65 will be stored in the character variable rather than 'A'.

How to Find ASCII Value in C?

Using the %d format specifier, we can print the ASCII value of a character.

Example Program 1: Display ASCII Value of a Character

                        
#include <stdio.h>
int main()  
{  
 char ch = 'A';  
 printf("The ASCII value of %c is: %d", ch, ch);  
 return 0;  
}
                        
                    

Output

The ASCII value of A is: 65

Example Program 2: Display ASCII Values of All Characters

                        
#include <stdio.h>
int main()  
{  
   for (int i = 0; i <= 127; i++)  
   {  
        printf("ASCII value of %c = %d\n", i, i);  
    }  
    return 0;  
}
                        
                    

Output (Partial)

ASCII value of = 32
ASCII value of ! = 33
ASCII value of " = 34
ASCII value of ~ = 126