C Example Code2026-03-252 min read
Print ASCII values of characters, numbers, and symbols in C using format specifiers. Explore ASCII conversion tables and character arithmetic.
Understanding ASCII in C
In C, characters (char) are stored internally as numeric integer codes following the American Standard Code for Information Interchange (ASCII).
'A'$→$ 65,'Z'$→$ 90'a'$→$ 97,'z'$→$ 122'0'$→$ 48,'9'$→$ 57
Complete C Source Code
c (ISO Standard)#include <stdio.h> void printAsciiInfo(char ch) { printf("Character: '%c' | Decimal ASCII: %3d | Hex: 0x%02X | Octal: %03o\n", ch, (unsigned char)ch, (unsigned char)ch, (unsigned char)ch); } int main() { char sampleChars[] = {'A', 'z', '0', '$', '\n', '\t'}; int count = sizeof(sampleChars) / sizeof(sampleChars[0]); printf("ASCII Code Inspector in C:\n\n"); for (int i = 0; i < count; i++) { printAsciiInfo(sampleChars[i]); } return 0; }
Sample Output
text (ISO Standard)ASCII Code Inspector in C: Character: 'A' | Decimal ASCII: 65 | Hex: 0x41 | Octal: 101 Character: 'z' | Decimal ASCII: 122 | Hex: 0x7A | Octal: 172 Character: '0' | Decimal ASCII: 48 | Hex: 0x30 | Octal: 060 Character: '$' | Decimal ASCII: 36 | Hex: 0x24 | Octal: 044 Character: ' ' | Decimal ASCII: 10 | Hex: 0x0A | Octal: 012 Character: ' ' | Decimal ASCII: 9 | Hex: 0x09 | Octal: 011
Complexity Analysis
- Time Complexity:
O(1)constant time casting. - Space Complexity:
O(1)stack variables.
Related Guides
- Format specifiers in Format Specifiers in C.
- Character analysis in Count Vowels and Consonants in C.