Problem Statement - Printable ascii codes
Write a c++ program to print ascii codes and given printable characters from decimal ascii code 32 to 126 (The printable ascii code range). Print each code and character set in a new line.
Solution
Run Output
Solved Problem Understanding
This code is fairly simple, just start the range from 32 which is a space character, which does not show anything but is still considered a printable character and the test condition goes up to ascii 126.
for(int i=32;i<=126;i++)
{
cout<<i<<“\t”<<(char)i<<endl;
}
The index i will print the ascii code as it is defined as an integer variable. The (char) typecasted version of i will print its corresponding character.
Notes
- The ascii code range has been designed in a way that the matter also remains in a sorted ascending order of digits and alphabets.
- The 7-bit ascii set starts with 0 and ends at 127. If you try the same question with 0 to 127 range some special characters will also be printed. These character shapes will be dependent on the code-page being used for the output, but the range 32-126 will always display the same character any any code page.
Suggested Filename(s): printable-ascii.cpp
