Isprint() in C++


The function isprint() is predefined function and it checks that the passed characters are printable or not. It returns non-zero value, if successful otherwise, zero. This function is declared in “cctype” header file.

Here is the syntax of isprint() in C++ language,

int isprint(int character);

Here,

character − The character is to be checked.

Here is an example of isprint() in C++ language,

Example

 Live Demo

#include<iostream>
#include<cctype>
using namespace std;
int main() {
   int val1 = 28;
   int val2 = 's';
   int val3 = '\n';
   if(isprint(val1))
   cout << "value is printable"<< endl;
   else
   cout << "value is not printable"<< endl;
   if(isprint(val2))
   cout << "value is printable"<< endl;
   else
   cout << "value is not printable"<< endl;
   if(isprint(val3))
   cout << "value is printable"<< endl;
   else
   cout << "value is not printable"<< endl;
   return 0;
}

Output

value is not printable
value is printable
value is not printable

In the above program, three variables are declared as val1, val2, and val3. Each variable is checked that variable is printable or not.

if(isprint(val1))
cout << "value is printable"<< endl;
else
cout << "value is not printable"<< endl;
if(isprint(val2))
cout << "value is printable"<< endl;
else
cout << "value is not printable"<< endl;
if(isprint(val3))
cout << "value is printable"<< endl;
else
cout << "value is not printable"<< endl;

Updated on: 26-Jun-2020

47 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements