C++ Program to Check Character is Uppercase, Lowercase, Digit, or Special Character

Below I have shared a C++ program to check whether a given character is an uppercase or lowercase alphabet, a digit, or a special character. First of all, I read a character and then compare it with the ASCII values given below.

  • Uppercase Alphabet: 65-90
  • Lowercase Alphabet: 97-122
  • Digit: 48-57

If the ASCII value of the character is other than the values mentioned above then it is a special character.

C++ Program to Check Given Character is Uppercase, Lowercase, Digit, or Special Character


using namespace std;

int main()
	char ch;
	cout<<"Enter any character: ";

		cout<<endl<<"You entered an uppercase character";
	else if(ch>=48&&ch<=57)
			cout<<endl<<"You entered a digit";
		else if(ch>=97&&ch<=122)
			cout<<endl<<"You entered a lowercase character";
			cout<<endl<<"You entered a special character";
	return 0;


Enter any character: F
You entered an uppercase character

Comment down below for any queries or suggestions.

7 thoughts on “C++ Program to Check Character is Uppercase, Lowercase, Digit, or Special Character”

  1. I have a question regarding this program.
    I tried writing this concept in form of nested if-else statements like the “dangling if-else statement”.
    if(expr 1)
    if(expr 2)
    statement 1;
    statement 2;
    the program doesn’t work… What’s wrong in this concept?
    Please do reply.

    1. Muhammad ul Hasnain

      this will only work if you cover all the character both lower and upper case in the main if. then compare whether it is lower or upper case. print the condition.
      else print ” special characters.
      if you don’t understand, you can email me.
      i will teach you there.
      make sure that you describe your self so i can know that its you otherwise i may ignore. 🙂
      email : mohdhasnain902@gmail.com

  2. it does not work properly I have copied your code and run
    it shows same msg on every input

    msg is that

    You entered a digit

  3. What would the statement be if you needed to write a program to check a single letter like if “Q” was upper or lower case?

    1. Muhammad ul Hasnain

      just input a single letter and it wil show you whether is is uppercase or lowercase.
      by the way, it can be implemented on any letter. thats why we chose this.

Leave a Comment

Your email address will not be published. Required fields are marked *