What is isgraph() in C?

The isgraph function is a C library function that checks if a character has a graphical representation. The characters which have a graphical representation can be printed, except for the whitespace characters. These characters are called graphic characters.

The graphic characters in C are as follows:

! " # $ % & ’ ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~

To use the isgraph function, the ctype.h header file needs to be included in the program, as shown below:

#include <ctype.h>

Syntax

The isgraph function requires a single argument and returns a single value. The function declaration is shown below:

int isgraph(char argument);

or

int isgraph(int argument);

Parameters

The isgraph function takes a single argument of the int or char type.

Return value

The isgraph function returns a non-zero value if the argument is a graphic character and returns a zero otherwise.

Example

The code below shows the use of isgraph function in C:

The character ‘3’ is printable hence, it returns a non-zero value. This confirms that it has a graphical representation.

#include <stdio.h>
#include <ctype.h>
int main() {
//Declare the character to be tested
int a = '3';
//Check for graphical representation
int answer;
answer = isgraph(a);
//Display answer
printf ("The character %c results in: %d\n", a, answer);
return 0;
}

The whitespace character returns a zero since it is not printable. Hence, it does not have a graphical representation, as we can see here:

#include <stdio.h>
#include <ctype.h>
int main() {
//Declare the character to be tested
char b = ' ';
//Check for graphical representation
int answer;
answer = isgraph(b);
//Display answer
printf ("The character %c results in: %d\n", b, answer);
return 0;
}

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved