isdigit() - Character Function
How is "isdigit()" used in C++?
Explanation
isdigit() function is used to check the character whether it is between 0-9 or a decimal. It returns zero when the argument is not a decimal or an integer in the given range.
Syntax:
int isdigit ( int c );
Example :
#include <iostream.h> #include <ctype.h> int main() { char a; cout<< "Enter a digit between 0-9: "; cin >> a; if (isdigit(a)) { cout << "Entered a digit\n"; } else { cout << "Not a digit\n"; } return 0; } |
Result :
Enter a digit between 0-9 : e
Not a digit
In the above example, this function is used to check if the entered character is a decimal or not. It has been checked using ASCII values.