char stores a character code. ASCII assigns values 0–127 to common English letters, digits, symbols, and control characters.
Converting between characters and integers
Convert a character to an integer to inspect its code, or convert a value from 0–127 to char to obtain the matching ASCII character. A digit character is not the number itself: '7' - '0' produces integer 7.
#include <stdio.h>
int main(void) {
char letter = 'A';
int code = (unsigned char) letter;
char next = (char) (code + 1);
printf("%c = %d, next = %c\n", letter, code, next);
return 0;
}INTERACTIVE LAB
Complete interactive ASCII atlas
ACCESSFREE
Select any value from 0–127 to inspect its character, decimal, hexadecimal, and binary representations.
Traversing ASCII
Control characters have no visible glyph, so a program should label values 0–31 and 127 separately.
for (int value = 0; value <= 127; value++) {
if (value >= 32 && value <= 126) {
printf("%3d %c\n", value, (char) value);
} else {
printf("%3d control\n", value);
}
}KNOWLEDGE QUIZ
QUESTION
What is the decimal ASCII value of 'A'?
HANDS-ON PRACTICE
Build an ASCII classifier
Read one ASCII character and classify it as uppercase, lowercase, digit, whitespace, or other.
- Read one character and keep its integer code.
- Use character ranges for digits and English letters.
- Handle space, tab, and newline as whitespace and print the category.