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?

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community