English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

Usage and example of C library function isxdigit()

C Standard Library <ctype.h>

The isxdigit() function checks if a character is a hexadecimal digit character (0-9, af, AF).

The function prototype of isxdigit() is:

int isxdigit(int arg);

It is<ctype.h>Defined in the header file.

isxdigit() parameter

The isxdigit() function takes a single character as a parameter.

Note:In C programming, characters are internally treated as int values.

C isxdigit() return value

If the argument passed to isxdigit() is

  • Hexadecimal character, isxdigit() returns a non-zero integer.

  • Non-hexadecimal character, isxdigit() returns 0.

Example1C isxdigit() function

#include <ctype.h>
#include <stdio.h>
int main() {
   char c = '5';
   int result;
   //Passing a hexadecimal character
   result = isxdigit(c); // Result is not zero
   printf("When %c is passed to isxdigit(): %d", c, isxdigit(c));
   c = 'M';
   //Non-hexadecimal character passed
   result = isxdigit(c); // result is 0
   printf("\nWhen %c is passed to isxdigit(): %d", c, isxdigit(c));
   return 0;
}

Output Result

When 5 Result when passed to isxdigit(): 128
Result when M is passed to isxdigit(): 0

Example2Program to check hexadecimal characters

#include <ctype.h>
#include <stdio.h>
int main() {
   char c = '5';
   printf("Enter a character: ");
   c = getchar();
   if (isxdigit(c) != 0) {}}
      printf("%c is a hexadecimal character.", c);
   } else {
      printf("%c is not a hexadecimal character.", c);
   }
   return 0;
}

Output Result

Enter a character: f
f is a hexadecimal character.

C Standard Library <ctype.h>