C++ ispunct()

ispunct() Prototype

int ispunct(int ch);

The ispunct() function checks if ch is a punctuation character as classified by the current C locale. By default, the punctuation characters are !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~.

The behaviour of ispunct() is undefined if the value of ch is not representable as unsigned char or is not equal to EOF.

It is defined in <cctype> header file.

ispunct() Parameters

ch: The character to check.

ispunct() Return value

The ispunct() function returns non zero value if ch is a punctuation character, otherwise returns zero.

Example: How ispunct() function works

#include <cctype>
#include <iostream>

using namespace std;

int main()
{
    char ch1 = '+';
    char ch2 = 'r';

    ispunct(ch1) ? cout << ch1 << " is a punctuation character" : cout << ch1 << " is not a punctuation character";
    cout << endl;
    ispunct(ch2) ? cout << ch2 << " is a punctuation character" : cout << ch2 << " is not a punctuation character";

    return 0;
}

When you run the program, the output will be:

+ is a punctuation character
r is not a punctuation character
Did you find this article helpful?