isalnum() function in C Language

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

Overview

The C library function isalnum() checks whether a character is alphanumeric (i.e., either alphabet or numeric digit) or not.

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Syntax of isalnum() in C

The syntax of the isalnum() function in C language is:

Where the isalnum() checks if the given character is alphanumeric or not, as classified by the current C locale.

In the default locale, the following characters are alphanumeric:

  • digits (0123456789)
  • uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ)
  • lowercase letters (abcdefghijklmnopqrstuvwxyz).

Parameters of isalnum() in C

The isalnum takes only one parameter, ch.

  • ch is the character that needs to be checked.
Sharpen Your Fundamentals with Free Learning

Return Values of isalnum() in C

Return Type: int

  • It returns a non zero value (i.e., true), if the given argument is either an alphabet or a digit (i.e., alphanumeric).
  • It returns zero (i.e., false), if the given argument is neither an alphabet nor a digit.

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Exceptions of isalnum() in C

The behavior of isalnum() is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.

Example to Check a Character is Alphanumeric or Not

Output

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

What is isalnum() in C?

The <ctype.h> header file declares several functions for classifying and transforming individual characters in the C language. The isalnum() function is among one of them.

The isalnum() function takes one argument and classifies if the argument is alphanumeric or not. The result is true if the given character is either an uppercase letter or lowercase letter, or a decimal digit.

Note:

  • If you look carefully, isalnum() takes an int argument, not a char. Functions like isalnum() take int arguments because functions like fgetc return int values, allowing special values like EOF to exist.
  • You do not need to convert the char to an int before passing it to isalnum(). The compiler will implicitly convert the char to an int before passing it.

More Examples

Example 1: To check a character is alphanumeric or not

Output

Explanation

This is the usual behaviour of the isalnum() function in c. It will return non-zero for alphanumeric characters and zero otherwise. The non-zero value can differ from compiler to compiler, but all of them denotes true.

Example 2: Counting alphanumeric characters in a string

Output

Explanation

Using the while loop, we are iterating over all the characters in the character array one by one. Within that, we check whether the character is alphanumeric and increases the counter accordingly. This will give the total number of the alphanumeric characters in the array, which is 18.

Conclusion

  • The isalnum() function is declared in ctype.h header file.
  • The isalnum() function of C checks if a given character is alphanumeric or not.
  • It returns non-zero value for alphanumeric characters and returns zero otherwise.
  • The compiler will implicity convert the given char to an int before passing it to the isalnum().