C isxdigit() - C Standard Library (2024)

The function prototype of isxdigit() is:

int isxdigit( int arg );

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

isxdigit() Parameters

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

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

C isxdigit() Return Value

If the argument passed to isxdigit() is

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

Example 1: C isxdigit() function

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

Output

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

Example 2: Program to Check Hexadecimal Character

#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

Enter a character: ff is a hexadecimal character.
C isxdigit() - C Standard Library (2024)
Top Articles
Latest Posts
Article information

Author: Duncan Muller

Last Updated:

Views: 6352

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.