C++ isgraph()

The isgraph() function in C++ checks if the given character is graphic or not.

isgraph() Prototype

int isgraph(int ch);

The isgraph() function checks if ch has a graphical representation as classified by the current C locale. By default, the following characters are graphic:

  • Digits (0 to 9)
  • Uppercase letters (A to Z)
  • Lowercase letters (a to z)
  • Punctuation characters (!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)

The behaviour of isgraph() is undefined if the value of ch is not representable as unsigned char or is not equal to EOF.

It is defined in <cctype> header file.

isgraph() Parameters

ch: The character to check.

isgraph() Return value

The isgraph() function returns non zero value if ch is graphic, otherwise returns zero.

Example: How isgraph() function works

#include <cctype>
#include <iostream>

using namespace std;

int main()
    char ch1 = '$';
    char ch2 = '\t';

    isgraph(ch1)? cout << ch1 << " has graphical representation" : cout << ch1 << " does not have graphical representation";
    cout << endl;
    isgraph(ch2)? cout << ch2 << " has graphical representation" : cout << ch2 << " does not have graphical representation";

    return 0;

When you run the program, the output will be:

$ has graphical representation
    does not have graphical representation
Did you find this article helpful?