Primary C Concepts: ASCII in C

Last Updated : 10 July, 2022 · 2 min read

articles banner image

ASCII (American Standard Code for Information Interchange) is an encoding scheme developed by Bob Bemer and first released in 1963. The standard ASCII consists of 128 bytes. Each byte, in turn, represents a different character value. ASCII code starts with 0 and ends with 127.

1. Representation of ASCII in C

In C programming language characters are not actually stored as characters in the memory, but rather as numeric ASCII representations of these characters. Because of this, each character can be printed as a character and as its numeric equivalent. Just like in the example below:

Example 1: C code to print numeric and char values.

#include <stdio.h>

int main ( void )
{
    
char c = 'B' ;
    
printf ( "1. Numeric: %d \n, 2. Char: %c" , c, c);
    
return (0);
}

Output:

1. Numeric: 66
2. Char: B

The standard ASCII table is often grouped into two subgroups, i.e., printable and control characters. The total number of printable characters is 95 (from 32 to 126). Whereas control characters amount to a total of 32 characters (from 0 to 31). In the C programming language printable characters, in turn, can be found with the isprint function. Control characters can be found with the help of iscntrl function.

2. What is ASCII used for?

Primarily and most importantly, ASCII encoding scheme is used to interchange information, just like the name suggests. And just like human communication, computers too require a shared encoding scheme, a language of a sort, to interchange information. Up until 2008, ASCII, together with Windows 1252 was the most commonly used encoding scheme worldwide. Then UTF-8 took the thrown and became the most commonly used encoding scheme.

3. Quiz of reader's knowledge

Quiz : ASCII in C

1What is the total number of printable ASCII characters?

2Of how many bytes does the standard ASCII consist of?

3Which of the following encoding schemes is the most commonly used today?

quiz completed!

Congrats!

Feel free to share your achievement below!