Boolean Functions in C++

Boolean function returns only true or false. If the condition is correct it returns true else it returns false. Boolean functions are used to find the correctness of the condition.

C++ uses a built-in library(cctype) that contains boolean functions like isdigit(), islower(), isupper() etc. These functions work only on characters

#include<iostream>
#include<cctype>
using namespace std;
int main(){
	char k;
	cout<<"Enter a character : ";
	cin>>k;
        cout<<"It is a ";
	if(isdigit(k))cout<<"Digit";
	else if(islower(k))cout<<"Lower Case";
	else if(isupper(k))cout<<"Upper Case";
	else cout<<"Other Character";
	return 0;
}
output of the above program, returns digit
output of the above program, returns digit
output of the above program, returns lower case
output of the above program, returns lower case

Other functions present are

  • isdigit(k)
  • islower(k)
  • isupper(k)
  • isspace(k)
  • iscntrl(k)
  • ispunct(k)

Try all of these functions.

One Reply to “Boolean Functions in C++”

Leave a Reply

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