TeachingBee

ASCII Table in C++

ascii table in c++

In this article we will into the ASCII table in C++, exploring its various character sets—from control characters to printable characters, including letters, digits, and special symbols—and demonstrates how to interact with these characters through C++ programming.

What is ASCII Table In C++?

The ASCII table is a character-encoding scheme originally based on the English alphabet. ASCII stands for American Standard Code for Information Interchange. It encodes 128 specified characters into seven-bit integers as shown by the ASCII standard. These characters include letters (both uppercase and lowercase), digits, punctuation marks, and non-printable control characters.

In total, there are 256 ASCII characters which can be divided into three types:

ASCII Control Characters

ASCII control characters are the first 32 characters in the ASCII table, ranging from 0 to 31. These characters are not printable and are used to control peripherals such as printers or to control the display of text. For example, ASCII 13 represents a carriage return.

ASCII Printable Characters

The ASCII printable characters start from 32 to 126 in the ASCII table. These characters include uppercase and lowercase letters, digits, punctuation marks, and a few miscellaneous symbols. For example, ASCII 65 represents the uppercase letter ‘A’, and ASCII 97 represents the lowercase letter ‘a’.

ASCII Printable Characters can be categorized into several types, including special characters, numbers, and alphabets.

1. Special Characters

Special characters in ASCII include punctuation marks, mathematical symbols, and other miscellaneous symbols that are neither letters nor numbers. These characters play crucial roles in formatting, operations, and syntax within programming and text representation.

Range:

  • Starting from ASCII code 32 (space) to 47 (/), which includes symbols like space, !, ", #, $, %, &, ', (, ), *, +, ,, -, ., and /.
  • From 58 (:) to 64 (@), including :, ;, <, =, >, ?, and @.
  • From 91 ([) to 96 (`), encompassing [, \\, ], ^, _, and `.
  • From 123 ({) to 126 (~), covering {, |, }, and ~.

2. Numbers

The ASCII table includes a range for decimal digits, making it straightforward to represent numbers in texts.

Range:

  • From 48 (0) to 57 (9). This range represents the ten decimal digits from 0 to 9.

3. Alphabets

ASCII characters include both uppercase and lowercase alphabets, allowing for a wide range of textual data representation.

Uppercase Alphabets Range:

  • From 65 (A) to 90 (Z). This range includes all 26 letters of the English alphabet in uppercase form.

Lowercase Alphabets Range:

  • From 97 (a) to 122 (z).This range includes all 26 letters of the English alphabet in lowercase form.
ascii value

ASCII 8: Extended ASCII Characters

The Extended ASCII is an 8-bit character set that includes the standard ASCII characters (0-127) and an additional 128 characters (128-255), bringing the total to 256. These additional characters include various symbols, diacritics, and graphical symbols. However, it’s important to note that the extended ASCII can vary depending on the system or standard being used (such as ISO-8859-1 or Windows-1252).

Some of the Extended ASCii characters:

ASCII ValueCharacterASCII ValueCharacterASCII ValueCharacterASCII ValueCharacter
128Ç144É160á176
129ü145æ161í177
130é146Æ162ó178
131â147ô163ú179
132ä148ö164ñ180
133à149ò165Ñ181
134å150û166ª182
135ç151ù167º183
136ê152ÿ168¿184
137ë153Ö169185
138è154Ü170¬186
139ï155¢171½187
140î156£172¼188
141ì157¥173¡189
142Ä158174«190
143Å159ƒ175»191

Programs To Print ASCII Value in C++

Let’s look some of the C++ programs to print ascii value.

C++ Program to Print ASCII Value of 0 to 9

#include<iostream>
using namespace std;

int main() {
    for(char c = '0'; c <= '9'; c++) {
        cout << "ASCII value of " << c << " is " << int(c) << endl;
    }
    return 0;
}

Output

ASCII value of 0 is 48
ASCII value of 1 is 49
ASCII value of 2 is 50
ASCII value of 3 is 51
ASCII value of 4 is 52
ASCII value of 5 is 53
ASCII value of 6 is 54
ASCII value of 7 is 55
ASCII value of 8 is 56
ASCII value of 9 is 57

Explanation: This program iterates from the character ‘0’ to ‘9’, converting each character to its ASCII integer value using type casting (int(c)) and prints it.

C++ Program To Print ASCII Value of a Character

#include<iostream>
using namespace std;

int main() {
    char c;
    cout << "Enter a character: ";
    cin >> c;
    cout << "ASCII value of " << c << " is " << int(c) << endl;
    return 0;
}

Output:

ASCII value of A is 65

Explanation: This program prompts the user to enter a character, then prints the ASCII value of the entered character by casting the character to an integer.

C++ Program to Print ASCII Value of A to Z using Type Conversion

#include<iostream>
using namespace std;

int main() {
    for(char c = 'A'; c <= 'Z'; c++) {
        cout << "ASCII value of " << c << " is " << static_cast<int>(c) << endl;
    }
    return 0;
}
ASCII value of A is 65
ASCII value of B is 66
ASCII value of C is 67
...
ASCII value of X is 88
ASCII value of Y is 89
ASCII value of Z is 90

Explanation: This program loops from ‘A’ to ‘Z’ and uses static_cast<int>() for type conversion to print the ASCII value of each uppercase letter.

Why is ASCII Table In C++ Important?

Understanding and using the ASCII table in C++ is crucial for various programming tasks, such as data encoding/decoding, character manipulation, and implementing communication protocols. It allows developers to work with characters in a standardized way, ensuring compatibility and predictability in how text is processed and displayed across different systems and platforms.

Check out

More C++ tutorials here

I hope You liked the post 👍. For more such posts, 📫 subscribe to our newsletter. Try out our free resume checker service where our Industry Experts will help you by providing resume score based on the key criteria that recruiters and hiring managers are looking for.

FAQ

What is ASCII 7 and ASCII 8?

ASCII 7, also known as 7-bit ASCII, is a character encoding standard that uses 7 bits to represent 128 unique characters, including letters, digits, and control characters. ASCII 8, or Extended ASCII, expands on this by using an extra bit (making it 8 bits in total) to represent 256 characters, allowing for additional symbols, special characters, and international characters not found in the standard ASCII set.

How to write ASCII code?

Writing ASCII code involves using numeric values to represent characters in text. For example, in programming, you can use the numeric ASCII value with a specific syntax (like \x41 for ‘A’ in C++ or Python) to insert characters into strings or to perform character operations. This approach allows programmers to directly manipulate text at its fundamental, numeric level, enabling precise control over data processing and display tasks.

90% of Tech Recruiters Judge This In Seconds! 👩‍💻🔍

Don’t let your resume be the weak link. Discover how to make a strong first impression with our free technical resume review!

Related Articles

basic oops concepts in c++

Basic OOPS Concepts in C++

Object-Oriented Programming (OOP) in C++ is a programming paradigm centered around objects that contain data and code. OOP models real-world entities, like customers or orders, as modular, reusable objects to

Finding lexicographically next permutation C++

Finding lexicographically next permutation C++

Problem Statement Given array of integers, rearrange the array such that, it becomes lexicographically next greater permutation of numbers i.e. if all the permutations are sorted according to their lexicographical

Why Aren’t You Getting Interview Calls? 📞❌

It might just be your resume. Let us pinpoint the problem for free and supercharge your job search. 

Newsletter

Don’t miss out! Subscribe now

Log In