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
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
- If the argument is a numeric character then it returns a non-zero value(true value).
- It returns zero(false value) if the argument is a non-numeric character.
Example: C Program to check whether the character is a digit or not using isdigit() Function
Entered character is numeric character
Working of isdigit() function in C
The working of the isdigit() function is as follows:
- STEP 1: The isdigit() function takes the character to be tested as the argument.
- STEP 2: The ASCII value of the character is checked.
- STEP 3A: If the ASCII value of the character is between 48 ( i.e ‘0’ ) and 57 ( i.e. ‘9’ ), a non-zero value (TRUE) is returned.
- STEP 3B: If the ASCII value of the character is not between 48 ( i.e ‘0’ ) and 57 ( i.e. ‘9’ ), Zero value (FALSE) is returned.
My Personal Notes arrow_drop_up
Please Login to comment...