Tokens In C++
Tokens in C++
In C++, the smallest individual unit in a program are known as tokens, C++ has the following tokens:
- Keywords
- Identifiers
- Constants
- Strings
- Operators
- Keywords
There are total 63 Keywords in C++ many of the Keywords are common in both C and C++, and some are added to increase the functionality and features.
- Identifiers
- Only alphabetic characters, digits and underscore are allowed.
- The name should start with the alphabet or underscore.
- Uppercase and lowercase letters are distinct.
- Keywords cannot be used as the identifier name.
- Constants
Constants refers to the fixed values that do not change during the execution of the program. C++ supports several types of literals constants, they include integer, characters, floating point numbers and strings. Literal constants do not have memory location.
Examples:
123 // integer literal
45.45 // floating point integer
024 // octal numbers
“Hello” // string literals
‘A’ // character literals
L’ab’ // wide character constant
The wchar_t type is a wide-character literal introduced by the ANSII C++ and is intended for character set that cannot fit in character into a single byte. Wide-character begins with the letter L.
- Strings
Strings are just the array of characters ending
with null character (‘\0’), the null character indicates the end of the string.
Strings are always enclosed in double quotes (“ ”), and the characters are
enclosed in single quotes (‘ ‘).
char string[] = {‘T’, ‘h’, ‘e’, “ “, ‘C’, ‘r’,
‘e’, ‘w’, ’\0’};
char string[] = “The Crew”;
- Operators
- Arithmetic operator (+, -, *, /, %)
- Logical operator (&&, ||, !)
- Relational operator (<, <=, >, >=, ==, !=)
- Assignment operator (=, +=, -=, *=, /=, %=)
- Conditional operator (expression ? expression : expression)
- Bitwise operator (&, |, ^, ~, <<, >>)
Comments
Post a Comment
if you have any doubts, let me know