Tokens in C++
In a C++ language, token is either a keyword, a symbol ,an identifier, a constant or a string literal.
A C++ program consists of various tokens for example, the following C++ program consists of four tokens
1 | cout<< “Hello”; |
The individual tokens are −
1 2 3 4 | cout << "Hello" ; |
Comments
Comments are the text in C++ program language and they are ignored by the compiler during compilation and execution.
They start with /* and terminate with the characters */ as shown below −
/* first C ++ program */
Anything written within Comment will never execute. You can’t write comments within comments.
This is a multi line comment.
We can also use single line comment.
Single line comment start with //
and continue until the end of the line.
Identifiers
In a C++ language, identifier is a name given to any variable, function, or any other user-defined item.
In C++ language identifier starts with a letter A to Z, a to z, digits (0 to 9) or an underscore ‘_’ followed by zero.
C++ language does not allow punctuation characters such as @, $, and % within identifiers.
Here are some examples of acceptable identifiers −
1 2 | kumar aditya abc move_name a_123 name70 j a23b9 myDemo |
Keywords
In a C++ language keywords are the reserved\predefined words whose meaning already explained in a compiler.
These reserved words can’t be used as a variables or identifier names.
There are 60 key words currently defined for C++.
C++ Keywords | ||||
---|---|---|---|---|
Asm | auto | bool | break | case |
catch | char | class | const_cast | continue |
default | delete | do | double | else |
enum | dynamic_cast | extern | false | float |
for | union | unsigned | using | friend |
goto | if | inline | int | long |
mutable | virtual | namespace | new | operator |
private | protected | public | register | void |
reinterpret_cast | return | short | signed | sizeof |
static | static_cast | volatile | struct | switch |
template | this | throw | true | try |
typedef | typeid | unsigned | wchar_t | while |