Before we get into more detail about C++ we want to lay some basic ground work.
Tokens
All source code is divided into a stream of tokens. A token can be an identifier, a reserved keyword, a literal, an operator, or punctuation symbol.
Identifiers
An identifier is a name that can define or be defined in a library. An identifier begins with a nondigit character (letter, an underscore, or one of the universal character) and is followed by any number of digits and nondigits.
There are some identifiers that are reserved and fall under two categories: function names and macro names.
Function names that should not be used are:
- is followed by a lower case letter
- mem followed by a lower case letter
- str followed by a lower case letter
- to followed by a lowercase letter
- wcs followed by a lower case letter
- In <cmath> with f or l appended
Macro names are reserved in all contexts.
Keywords
A keyword is an identifier that is reserved in all contexts.
The following is a list of reserved keywords:
Literals
A literal is an integer, floating point, Boolean, character, or string constant
Integer Literals – An integer literal can be a decimal, octal, or hexadecimal constant.
Floating point literals – A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part.
boolean literals – there are two Boolean literals: true and false
Character literals – character literals are enclosed in single quotes. A wide character literal begins with an uppercase L (e.g., L’x’) while a narrow character literal does not (e.g., ‘x’).
String literals – String literals are enclosed in double quotes. They are similar to character literals.
Symbols
Symbols are nonalphabetic symbols used as operators and as punctuation.
Comments
Comments start with /* and end with */. These comments do not nest.
A comment can also start with //. A // comment can nest in a /* */ comment.
Escape Sequences
Escape sequences are backslashes followed by a character.