Open In App

isdigit() function in C/C++ with Examples

The isdigit() in C is a function that can be used to check if the passed character is a digit or not. It returns a non-zero value if it’s a digit else it returns 0. For example, it returns a non-zero value for ‘0’ to ‘9’ and zero for others.

The isdigit() function is declared inside ctype.h header file.



C isdigit() Syntax

isdigit(int arg);

C isdigit() Parameters

This function takes a single argument in the form of an integer and returns the value of type int.

Note: Even though isdigit() takes an integer as an argument, the character is passed to the function. Internally, the character is converted to its ASCII value for the check.



C isdigit() Return Value

This function returns an integer value on the basis of the argument passed to it

Example: C Program to check whether the character is a digit or not using isdigit() Function




// C program to demonstrate isdigit()
#include <ctype.h>
#include <stdio.h>
  
// Driver Code
int main()
{
    // Taking input
    char ch = '6';
  
    // Check if the given input
    // is numeric or not
    if (isdigit(ch))
        printf("Entered character is"
            " numeric character");
    else
        printf("Entered character is not"
            " a numeric character");
    return 0;
}

Output
Entered character is numeric character

Working of isdigit() function in C

The working of the isdigit() function is as follows:

Article Tags :