Académique Documents
Professionnel Documents
Culture Documents
1 of 7
http://gradestack.com/Programming-in-C-/C-Declarations/Tokens/2119...
Explore (/mainsite/explorecourse)
(http://gradestack.com/)
Login (/web/login)
Tokens
The smallest individual unit in a program is known as token.
C++ programs contain various components. The compiler
identifies them as tokens. Tokens are classified into the
following types and are also indicated in Figure.
1. Keywords Reserved by the compiler.
2. Identifiers Names of variables, arrays, classes,
functions, etc. are identifiers.
3. Constants Constants are fixed values.
4. Operators Operators are different types and are used
in expressions.
5. String Sequence of characters.
The keywords are reserved set of words with fixed meanings.
The variables are used to hold data temporarily. The
operators are used to perform different operations such as
arithmetic and logical. Values such as 1, 5, 2.5, etc. are
known as constants. The operators such as #, ?, and ~ are
known as special characters. The # is used for preprocessor
directive; ? is a conditional operator; and ~ is used for bitwise
operation. The detailed descriptions of these tokens are
described in following sections.
Types of tokens
Comment
Like 0
Share
Keywords
The C++ keywords are reserved words by the compiler and
are assigned fixed meanings. All C keywords are valid in
C++. The programmer may not apply them in the programs
for defining variable names; however, few C++ compilers
permit to declare variable names that exactly match with the
keywords.
The common keywords between C and C++ are listed in Table
4.1 and the additional keywords of C++ are listed in Table 4.2.
These keywords are used with classes, templates, and
exception handling, etc. Table 4.3 contains keywords added
by ANSI committee. Table 4.4 contains additional keywords
provided by Turbo C++ compiler.
double
int
struct
break
else
long
switch
case
enum
register
typedef
char
extern
return
union
const
float
short
unsigned
continue
for
signed
void
default
goto
sizeof
volatile
do
if
static
while
private
catch
protected
class
public
delete
template
friend
this
inline
throw
new
try
operator
virtual
const_cast
mutable
typename using
dynamic_cast
wchar_t
explicit
export
true
typeid
03-Jul-16 11:21 AM
2 of 7
http://gradestack.com/Programming-in-C-/C-Declarations/Tokens/2119...
_cs
_ds
_es
_fastcall
huge
interrupt
_loads
pascal
_saveregs
_seg
_ss
Comment
far
near
Like 0
Share
Identifiers
Each variable is represented by a symbol using identifiers.
Identifiers are names of variables, functions, arrays, etc. In
other words, identifiers refer to variety of entities such as
structures, unions, enumeration, constants, typedef names,
functions, and objects (refer Figure).
Types of tokens
Comment
Like 0
Share
Constants
The constants in C++ are applicable to the values that do
not change during execution of a program. There are several
types of constants in C++. They are classified into the
following groups as shown in Figure 4.3 and Table 4.5.
C++ constants
Constant Type
542
Integer constant
35.254
0x54
0171
Character constant
cpp
String constant
Numerical Constants
Integer Constants:
Integer constants are represented with whole numbers. It
requires minimum two bytes and maximum four bytes of
memory.
03-Jul-16 11:21 AM
3 of 7
http://gradestack.com/Programming-in-C-/C-Declarations/Tokens/2119...
Single-character constants:
03-Jul-16 11:21 AM
http://gradestack.com/Programming-in-C-/C-Declarations/Tokens/2119...
Tokens
4 of 7
Example:
const int price=152;
The above declaration defines a constant of type int. Here,
data type is strictly maintained while execution and the value
of constant cannot be changed during run-time.
4.3 Program on const keyword.
03-Jul-16 11:21 AM
http://gradestack.com/Programming-in-C-/C-Declarations/Tokens/2119...
Tokens
5 of 7
Example:
Example:
// k=5; // possible
// pm++; // possible
Example:
Example:
enum {a,b,c};
enum [a=5,b=10,c=15};
03-Jul-16 11:21 AM
6 of 7
http://gradestack.com/Programming-in-C-/C-Declarations/Tokens/2119...
Comment
Like 0
Share
Painting Contractors
Operators
C++ supports all the operators of C. In addition, C++
introduces few more operators. The new operators are <<, >>,
::, ::*, ->*,.*, delete, new, etc.
Like 0
Share
String Constants
String is represented by an array of characters. String
constants are enclosed in double quotes. Following are the
valid examples of string constants.
Like 0
Share
Next
(http://a.tribalfusion.com/h.click
/anmQwvRrZavPW 3dVG3U4b6rnWZaoYq2M4dMCPGZbZc4AJIodPOVHJhYbviYbbk1qqpRrMCUUQSWdQ0nFBpRUjpYars5T3c5qvRoEBIXFU9WHjXmPQCmV7mmW 7A3aZbg5tEq56rZbmFbZd0GnWYVF10sb
/http://www.cidi.org
/NepalRelief?utm_medium=banner&
utm_source=exponential&
utm_campaign=adcouncil&
utm_content=nepal)
(http://a.tribalfusion.com/h.click
/aamQwv1cnVXVFwmEBT3rFRWrJDVAU0REM2PcrOQHUw1tnxTmMp3sQWXbnZcU6iq4AvdP6jK3HUo1dQIpdEO5AnS4GUaVVYjUsB8S6FuW dv3UbFS2r2oUabmVqJaSTrZdSs3JQFuoPHv7W cbR4ryxmtqq0q
/http://www.cidi.org
/NepalRelief?utm_medium=banner&
utm_source=exponential&
utm_campaign=adcouncil&
utm_content=nepal)
03-Jul-16 11:21 AM
7 of 7
About Us (/mainsite/aboutus)
Contact Us (/mainsite/contact)
Developers (/mainsite/developer)
http://gradestack.com/Programming-in-C-/C-Declarations/Tokens/2119...
News (/mainsite/news)
Blog (/blog/)
03-Jul-16 11:21 AM