Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

ispunct — C23 character classification function

`ispunct(c)` from `<ctype.h>` returns a nonzero value for a punctuation character: a printing character that is neither space nor alphanumeric in the current locale. Underscore is punctuation even though C permits it in identifiers.

Version: C23

Syntax

int ispunct(int c);

ispunct(c) from <ctype.h> returns a nonzero value for a punctuation character: a printing character that is neither space nor alphanumeric in the current locale. Underscore is punctuation even though C permits it in identifiers.

The example tests !, _, A, and 7 in the C locale and normalizes with != 0. Output 1 1 0 0 demonstrates two punctuation characters and rejects a letter and a digit.

The argument must be EOF or representable as unsigned char; a negative plain char has undefined behavior. For a byte use ispunct((unsigned char)ch), preserving EOF separately. The result follows LC_CTYPE; do not use it as a complete Unicode punctuation test or as a C identifier-syntax validator.

Examples

#include <ctype.h>
#include <stdio.h>
int main(void){int values[]={'!','_','A','7'};printf("%d %d %d %d\n",ispunct(values[0])!=0,ispunct(values[1])!=0,ispunct(values[2])!=0,ispunct(values[3])!=0);return 0;}

Result

1 1 0 0

The example tests `!`, `_`, `A`, and `7` in the `C` locale and normalizes with `!= 0`. Output `1 1 0 0` demonstrates two punctuation characters and rejects a letter and a digit.

Sources