C isdigit() Function Tutorial

In this section, we will learn what the isdigit() function is and how to use it in C.

isdigit() in C

The `isdigit()` function is used to check whether a character is a `number`. (0-9)

The prototype of the function exists in the `ctype.h` header file and we need to include this header file in order to use the ` isdigit ()` function.

isdigit() Function Syntax

Here’s the prototype of the ` isdigit ()` function:

int isdigit(int argument);

isdigit() Function Parameters

This function takes one argument and that is the character that we want to check.

isdigit() Function Return Value

The return value of the function is:

  • 0: If the character was not a `number`.
  • Positive value: if the character was in fact a `number`.

Example: using isdigit() function in C

#include <stdio.h>
#include <ctype.h>

int main() {

    char character = 'a';
    char c2 = '4';

    printf("The first character: %d \nThe second character: %d", isdigit (character), isdigit (c2));

    return  0;


The first character: 0

The second character: 2

The first character in this example is `a` and so the result of calling the `isalnum` function is 0 value because `a` is not a number. But the result of the second character is a positive value because the actual value of the character is `4` and it’s a `number`.


Top Technologies