In a passage of text, individual words and punctuation marks are called tokens, lexical units or lexical elements. C++ has the following tokens :
Keywords are the words that convey a special meaning to the language compiler. These are reserved for special purpose and must not be used as normal identifier names.
Identifiers are fundamental building blocks of a program and are used as the general terminology for the names given to different parts of the program.
The following are some valid identifiers :
The following are some invalid identifiers :
Literals are are data items that never change their value during a program run. C++ allows server kinds of literals :
The bool literal in C++ is used to represent one of the two boolean values (true - boolean true or false - boolean false). Internally boolean true has value of 1 and boolean false has value of 0.
Integer constants are whole numbers with out any fractional part. The method of writing integer constants has been specified in the following rule :
A character constant is one character enclosed in single quotes, as in 'Z' ( Escape Sequences in C++ ) .
Real constants are numbers having fractional parts. The following are valid real constants in fractional form :
2.0
, 17.5
, -15.0
, -0.15255
The following are invalid real constants :
7
- No decimal point 7.
- No digit after decimal point +17/6
- '/' Illegal symbol 525.68.01
- Two decimal points 5258,01
- comma not allowed
'Multiple Character' constants are treated as string literal. A string literal is a sequence of characters surrounded by double quotes ( "abcd" ).
The following characters are used as punctuator is C++:
Opening and closing brackets indicate single and multidimensional array subscripts.
Opening and closing parentheses indicate function calls and function parameters. Parentheses also group expressions and isolate conditional expressions.
Opening and closing braces indicate the start and end of compound statement (block of code containing more than one executable statements).
It is used as a separator in a function arguments lists.
It is used as a statement terminator. Every executable statement is terminated by a semicolon (;).
It indicates a labeled statement.
It is used for pointer declaration and the asterisk is also used as an operator to either pointer or as the multiplication operator.
Ellipsis (...) are used in the formal argument lists of function prototypes to indicate a variable number of argument.
It is used for variable initial and as an assignment operator in expressions.
The pound sign(#) is used for preprocessor directive and double pound sing(##) is also used as operators to perform token replacement and during the preprocessor scanning phase.
Operators and Expressions - Operators are tokens that trigger some computation when applied to variables and other objects in an expression. The following list gives a brief description of the operators and their functions :
Unary operator are those operators that require one operator to operate upon. following are some unary operators :
Binary operators are those operators that require two operands to operate upon. following are some binary operators :
Arithmetic Operators | |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Remainder / Modulus |
Shift Operators | |
---|---|
<< | shift left |
>> | shift right |
Bitwise Operators | |
---|---|
& | Bitwise AND |
^ | Bitwise exclusive OR (XOR) |
| | Bitwise OR |
Logical Operators | |
---|---|
&& | Logical AND |
|| | Logical OR |
Assignment Operators | |
---|---|
= | Assignment |
/= | Assign quotient |
+= | Assign sum |
<<= | Assign left shift |
&= | Assign bitwise AND |
*= | Assign product |
%= | Assign remainder |
-= | Assign difference |
>>= | Assign right shift |
^= | Assign bitwise or (XOR) |
Relational Operators | |
---|---|
< | Less than |
> | Greater than |
<= | Less than or equal to |
>= | Greater than or equal to |
== | Equal to |
!= | Not equal to |
Component selection Operators | |
---|---|
Direct component selector | |
Indirect components selector |
Class member Operators | |
---|---|
:: | Scope access/resolution |
.* | Deference pointer to class member |
-->* | Deference pointer to class member |
Conditional Operators | |
---|---|
? | Ternary |
: | Ternary |
Escape Sequence | Non-graphic Character |
---|---|
\a | Audible bell (alert) |
\b | Backspace |
\f | Formfeed |
\n | Newline or linefeed |
\r | Carriage Return |
\t | Horizontal tab |
\v | Vertical tab |
\\ | Backslash |
\' | Single quote |
\" | Double quote |
\? | Question mark |
\On | Octal number |
\xHn | Hexadecimal number |
\0 | Null |
It's a special area where you can find special questions and answers for CSE students or IT professionals. Also, In this section, we try to explain a topic in a very deep way.