Does C and C++ ensure the ASCII codes for a-z and A-Z characters?

The ASCII codes for lowercase letters “a-z” and uppercase letters “A-Z” are consistent across various systems and programming languages, including C/C++. This consistency ensures that the ASCII codes of these characters remain the same on any system that supports ASCII encoding. The ASCII ranges for uppercase and lowercase letters is given below:

ASCII Range for Upper and Lowercase Letters

Upper letters

ASCII values range

A–Z

65–90

Lower letters

ASCII values range

a–z

97–122

Moreover, as the ASCII codes for these characters are sequential and ascending, we can use a loop in C/C++ to iterate through, as follows:

#include <iostream>
using namespace std;
int main() {
char symbol;
// print ASCII values of A-Z
for (symbol = 'A'; symbol <= 'Z'; symbol++)
{
cout << symbol << ": " << (int)symbol <<endl;
}
// print ASCII values of a-z
for (symbol = 'a'; symbol <= 'z'; symbol++)
{
cout << symbol << ": " << (int)symbol <<endl;
}
return 0;
}
Print the ASCII values in C++

Explanation

  • Line 5: A variable named symbol of type char is declared to store characters.

  • Line 8–11: This block of code represents a for loop that iterates over the uppercase letters from A to Z. It initializes symbol with A and continues the loop as long as symbol is less than or equal to Z. In each iteration, it prints the current value of symbol, followed by a colon and the ASCII value of the character obtained by casting symbol to an integer using (int)symbol.

  • Line 14–17: This block of code represents another for loop that iterates over the lowercase letters from a to z. It initializes symbol with a and continues the loop as long as symbol is less than or equal to z. In each iteration, it prints the current value of symbol, followed by a colon and the ASCII value of the character obtained by casting symbol to an integer using (int)symbol.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved