Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c++
iscntrl
communitycreator

What is iscntrl() in C++?

Salman Yousaf

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In the object oriented language C++, iscntrl() checks control characters. Their range is from 1 to 31 or 127 in ASCII.

Control Characters are those values in the ASCIIAmerican Standard Code for Information Interchange that do not have a specific symbol. These character values on ASCII are used for signaling purposes in computers.

Syntax


int iscntrl(char ch)

Parameters

ch: this function takes a character of type char as a parameter.

Return value

  • If argument values are in range (1-31 or 127), it will randomly return a non-zero value.

  • If the argument is not between the defined range(1-31 or 127), it will return zero.

Code

In the example below, we pass * as an argument to the iscntrl() method as highlighted, i.e., line 7. The output of this code will be Not a Control Character because * (ASCII: 42) is not a control character.

#include <iostream>
using namespace std;
int main() {
// taking asteric as input
// Asteric is not a controll character
if(iscntrl('*')){
cout << "Control Character\n";
} else
cout << "Not a Control Chracter\n";
// taking \t as input
// \t is a controll character
if(iscntrl('\t')){
cout << "Control Character\n";
} else
cout << "Not a Control Chracter\n";
return 0;
}

RELATED TAGS

c++
iscntrl
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring