The isalnum() function in C is used to determine whether a character is an alphanumeric character (a letter or a digit). It returns an integer value that indicates the result of the check.
The return values of the isalnum() function are as follows:
- Non-zero value: If the character is an alphanumeric character (a letter or a digit), the function returns a non-zero value. Typically, this value is 1 to indicate true or success.
0 (zero): If the character is not an alphanumeric character, the function returns zero to indicate false or failure.
The isalnum() function is part of the <ctype.h> header in C, which provides functions for character classification based on their types.
In C, the isalnum() function is used to check whether a character is alphanumeric or not. It is defined in the <ctype.h> header file and returns an integer value.
The possible return values of isalnum() are:
- If the character is alphanumeric (a letter or a digit), the function returns a nonzero value (true).
- If the character is not alphanumeric, the function returns zero (false).
Here’s an example usage of isalnum():
<span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string"><stdio.h></span></span>
<span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string"><ctype.h></span></span>
<span class="hljs-type">int</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span> {
<span class="hljs-type">char</span> ch = <span class="hljs-string">'A'</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-built_in">isalnum</span>(ch)) {
<span class="hljs-built_in">printf</span>(<span class="hljs-string">"%c is alphanumeric.\n"</span>, ch);
} <span class="hljs-keyword">else</span> {
<span class="hljs-built_in">printf</span>(<span class="hljs-string">"%c is not alphanumeric.\n"</span>, ch);
}
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}
In this example, the isalnum() function is used to check if the character 'A' is alphanumeric. Since it is a letter, the function returns a nonzero value, indicating that it is alphanumeric.
