C++ Program to check whether a character is uppercase, lowercase ,digit or special character

Character is uppercase ,lowercase ,digit or special character

Here we will discuss C++ program to check whether a character is uppercase, lowercase ,digit or special character. As there are different types of character in C++, so we’ll learn to write a code to do so.

C++ Program to check whether a character is uppercase, lowercase ,digit or special character

Program to check whether a character is uppercase, lowercase ,digit or special character

In C++ programming language a char type variable can store many different types of values ,128 values in total, single value at a time. Each value has been assigned a code by which they can be identified and that is called ASCII code.

  • Alphabets
    • Uppercase( between 65 to 90 )
    • Lowercase( between 97 to 122)
  • Digits (between 48 to 57)
  • Special Characters (all the remaining in between 0 to 127)
Character is uppercase ,lowercase ,digit or special character

Working:

  • User gives an input.
  • The input is stored in a char type variable say prep.
  • prep is then checked using the if else-if statement.
  • For uppercase alphabets
if((prep >= 65) && (prep <= 90))
  • For lowercase alphabets
else if((prep >= 97) && (prep <= 122))
  • For digits
else if((prep >= 48) && (prep <= 57))
  • All others will be the special characters.

C++ code

Run
//C++ program
//Character is alphabet, a digit, or a special character
#include <iostream>
using namespace std;
int main()
{
    char charCheck;
    cout<<"Enter a character: "; cin>>charCheck;
    //for uppercase alphabets
    if((charCheck >= 65) && (charCheck <= 90)) 
    {
        cout<<charCheck<<" is Uppercase Alphabet"; } // for lowercase alphabets else if((charCheck >= 97) && (charCheck <= 122))
    {
        cout<<charCheck<<" is Lowercase Alphabet"; } //for digits else if((charCheck >= 48) && (charCheck <= 57))
    {
        cout<<charCheck<<" is a Digit";
    }
    //all remaining are special characters
    else
    {
        cout<<charCheck<<" is a Special Character";
    }
    return 0; 
}

Output:

Enter a character: @

@ is a Special Character

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription

Getting Started