Popular Tutorials
Start Learning C++Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
C++ ispunct()
The ispunct() function in C++ checks if the given character is a punctuation character or not.
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?