Ticker

6/recent/ticker-posts

C++ Character Set, Tokens, Identifiers, Keywords

C++ Character Set

Character set is a set of valid characters that a language can recognise. The character set of C++ is consisting of letters, digits, and special characters. The C++ has the following character set:

Letters (Alphabets) ::  A------Z, a-------z 

Digits :: 0------9 

Special Characters ::  +, -, *, /, ^, \, ( ), [ ], { }, =, !, < >. „, ", $, ;, :, % , &, ?, _, #, <=, >=, @

There are 62 letters and digits character set in C++ (26 Capital Letters + 26 Small Letters + 10 Digits) as shown above. Further, C++ is a case sensitive language, i.e. the letter A and a, are distinct in C++ object oriented programming language. There are 29, punctuation and special character set in C++ and is used for various purposes during programming.

White Spaces Characters:

 A character that is used to produce blank space when printed in C++ is called white space character. These are spaces, tabs, new-lines, and comments. 

Tokens: 

A token is a group of characters that logically combine together. The programmer can write a program by using tokens. C++ uses the following types of tokens: 

  • Keywords 
  • Identifiers 
  • Literals 
  • Punctuators 
  • Operators 

Identifiers 

 A symbolic name is generally known as an identifier. Valid identifiers are a sequence of one or more letters, digits or underscore characters (_). Neither spaces nor punctuation marks or symbols can be part of an identifier. Only letters, digits and single underscore characters are valid. 

In addition, variable identifiers always have to begin with a letter. In no case can they begin with a digit. Another rule for declaring identifiers is that they cannot match any keyword of the C++ programming language. The rules for the formation of identifiers can be summarised as:

An identifier may include of alphabets, digits and/or underscores. It must not start with a digit. 

C++ is case sensitive, i.e., upper case and lower case letters are considered different form each other. It may be noted that TOTAL and total are two different identifier names. 

It should not be a reserved word. 

A member function with the same name as its class is called constructor and it is used to initialize the objects of that class type with an initial value. Objects generally need to initialize variables or assign dynamic memory during their process of creation to become operative and to avoid returning unexpected values during their execution. For example, to avoid unexpected results in the example given below we have initialized the value of rollno as 0 and marks as 0.0.

Keywords 

There are some reserved words in C++ which have predefined meaning to complier called keywords. These are also known as reserved words and are always written or typed in lower cases. There are following keywords in C++ object oriented language: 

List of Keywords: 

asm             double                 new             switch             auto 

else             operator             template         break             enum 

private             this                 case             extern             protected 

try                 catch                 float             public             typedef 

char                 for                 register         union                 class 

friend             return             unsigned         const                 goto 

short             virtual             continue             if                 signed 

void             default                 inline         sizeof               volatile 

delete             int                     static             while                 do 

long             struct