TOKENS, C++
Tokens
A token is the smallest element of a C++ program that is meaningful to the compiler. The C++ recognizes the following tokens:
A token is the smallest element of a C++ program that is meaningful to the compiler. The C++ recognizes the following tokens:
- Identifiers
- Keywords
- Literals / Constants
- Operators
- String
Tokens are usually separated by white space. White space can be one or more blanks, Horizontal or Vertical tab, New lines, Form feeds, Comments.
Identifiers
An identifier is a sequence of characters. Which are used to denote object or variable name, class, structure, or union name, functions name etc. Doesn't use the keywords as a Identifiers, it will get error.
Keywords
Keywords are predefined reserved identifiers that have special meanings. They cannot be used as identifiers in the program. C++ reserved Keywords are listed following.
asm
|
default
|
goto
|
register
|
throw
|
auto
|
delete
|
if
|
return
|
try
|
bool
|
do
|
inline
|
short
|
typedef
|
break
|
double
|
int
|
signed
|
union
|
case
|
else
|
long
|
sizeof
|
unisigned
|
catch
|
enum
|
new
|
static
|
virtual
|
char
|
extern
|
operator
|
struct
|
void
|
class
|
float
|
private
|
switch
|
volatile
|
const
|
for
|
protected
|
template
|
while
|
continue
|
friend
|
public
|
this
|
Literals / Constant
Invariant program elements are called "Literals" or Constants". Constants means the program may not alter the fixed value and they called literal. The terms 'Literal' and ' constant' are used interchangeably here. Literals fall into four major categories. They are integer, character, floating point and string literals.
Character Constant: The character type is used to store characters. 'char' keyword is used to declare these types of variable. Range of character type is -128 to 127 and size is one byte.
Integer Constant: The integer type is used for storing whole numbers without fraction parts. We can use signed, unsigned or plain integer values. Integer values come in three sizes, plain int, short int, long int. The range of values of these types will be defined by compiler. Normal range is -32768 to 32767. Size is 2 bytes.
Floating Constant: Floating constants contain decimal numbers. They are also called Real Constant. It consist of signed or unsigned digits including a decimal points, for example 1.16, - .085.
Operator
Operator are special symbols used for specific purpose. C++ provides six types of Operators.
String
String is represented by a group of characters. String constant are enclosed in double quotes.
Operator
Operator are special symbols used for specific purpose. C++ provides six types of Operators.
- Arithmetic Operator
- Relational Operator
- Logical Operator
- Unary Operator
- Assignment Operator
- Conditional Operator
- Comma Operator
String
String is represented by a group of characters. String constant are enclosed in double quotes.
0 comentários:
Post a Comment