The character set includes various mathematical symbols, like the Digits and Special characters, along with the Alphabets and Spaces in English. The phrase "C++ character set" pertains to the characters and symbols understood and accepted by C++ programs. These elements are amalgamated to create and deliver the instructions, statements, expressions, keywords, and other entities of the C++ language.
It fundamentally involves merging alphabets or characters, symbols, numbers, and spaces in a manner akin to the process of mastering the English language, starting with alphabets, then progressing to combining them to form words. Subsequently, these words are strung together to form sentences, and these sentences are grouped to form paragraphs. To elaborate, a C++ code is essentially a sequence of characters arranged in a specific order. Within the C++ compiler, these characters fulfill various functions within the character set.
C++ employs a mix of characters along with escape sequences to represent certain situations. For example, the newline, backspace, and horizontal tab are denoted by the character combinations "nt", "b", and "t".
These are categorized as below:
| Sr.no | Category | Character |
|---|---|---|
1. |
Alphabets | A B C D E F G H I J K L M N O P Q R S T U V W X Y Za b c d e f g h i j k l m n o p q r s t u v w x y z |
2. |
Digits | 0 1 2 3 4 5 6 7 8 9 |
3. |
Special characters | - * / A () [] {} = <> . ' " $ , ; : % ! & ? _ (underscore) # @ |
4. |
White spaces | Space bar (Blank space), Horizontal Tab (? ), |
1. Alphabets
Alphabets in C++ are denoted by either uppercase (A-Z) or lowercase (a-z) characters, with each case having distinct significance due to the language's case-sensitive nature. This feature simplifies the process of writing C++ code and defining character constants. Consequently, C++ programming encompasses the entire set of 26 letters for creating statements and character representations.
2. Digits
The numbers 0 through 9 symbolize the Digits, either individually or in various combinations. Numeric values can be effortlessly expressed using Digits. Numerical information can also be assigned to C-tokens. Within C++ coding, any of the ten Digits, ranging from 0 to 9, can be employed.
3. Special symbols
The term "Special characters" encompasses all keyboard keys besides letters, numbers, and spaces. This includes punctuation marks and distinct symbols utilized for quoting or specific functions.
Approximately thirty special characters are accessible for utilization in C++ programming. Moreover, these symbols are essential for constructing arithmetic equations such as +, -, *, relational expressions like >, =, >=, ==, assignment operations like =, and logical conditions like &&, ||, and more.
4. White Spaces
For particular use cases, White Spaces serve various purposes such as creating empty space, starting a new line, adding horizontal tab space, initiating a form feed, controlling carriage return, and more. It is important to highlight that the Turbo-C Compiler consistently disregards these white space characters in both high-level and low-level coding.
Example of a C++ Character Set:
You can observe an illustration of character sets utilization in the C++ programming language in the subsequent program:
#include<iostream>
using namespace std;
int main()
{
char myChar, myDigit, mySymbol;
cout<< "Enter a character: ";
cin>>myChar;
cout<< "You entered a character: " <<myChar<<endl;
cout<< "\nEnter a Digit: ";
cin>>myDigit;
cout<< "You entered a Digit: " <<myDigit<<endl;
cout<< "\nEnter a symbol: ";
cin>>mySymbol;
cout<< "You entered a symbol: " <<mySymbol<<endl;
return 0;
}
Output:
Enter a character: A
You entered a character: A
Enter a Digit: 5
You entered a Digit: 5
Enter a symbol: #
You entered a symbol: #