Tokens In C++

C++ Tokens

Tokens In C++ : Tokens are basic building block of C++ programming which is meaningful to the interpreter. By using which we can create a program. There are following categories of tokens :

  1. Identifier
  2. Keywords
  3. Constant
  4. Operators

IDENTIFIERS

Identifiers are the names given to various program elements such as variables, functions
and arrays. These are user defined names consisting of sequence of letters and digits.



Rules for declaring identifiers:


i. The first character must be an alphabet or underscore.
ii. It must consist of only letters, digits and underscore.
iii. Identifiers may have any length but only first 31 characters are significant.
iv. It must not contain white space or blank space.
v. We should not use keywords as identifiers.

Note : Upper and lower case letters are different.

Example

ab Ab aB AB are treated differently

Examples of valid identifiers:

a, x, n, num, SUM, fact, grand_total, sum_of_digits, sum1

Examples of Invalid identifiers:

$amount, ³num´, grand-total, sum of digits, 4num.


KEYWORDS

There are certain words, called keywords (reserved words) that have a predefined meaning in
„C++? language. These keywords are only to be used for their intended purpose and not as identifiers. The following table shows the standard „C++ reserved keywords.

auto defaultfloatdeletethissizeoftrysigned
break doforinlinecatchstaticthrowtemplate
casedoublegotolongregisterswitchvoidstruct
charelseifwhilefriendtypedefvolatileshort
constenumintclassnewunionunsignedreturn
continueexternpublicprotectedprivate

CONSTANTS

Constants refer to values that do not change during the execution of a program,
these can be divided into two major categories:

1.Primary constants:

a)Numeric constants
?Integer constants.
?Floating-point (real) constants.

b)Character constants

i. Single character constant
ii. String constants

2.Secondary constants:

i. Enumeration constants.
ii.Symbolic constants.
iii. Arrays, unions, etc.


Rules for declaring constants:

1.Commas and blank spaces are not permitted within the constant.
2.The constant can be preceded by minus (-) signed if required.
3.The value of a constant must be within its minimum bounds of its specified data type.


OPERATORS AND EXPRESSIONS

An operator is a symbol which represents a particular operation that can be performed on data. An operand is the object on which an operation is performed. By combining the operators and operands we form an expression. An expression is a sequence of operands and operators that reduces to a single value.


Spread the love

1 thought on “Tokens In C++”

  1. Pingback: Operators In C++ - AskAtul.com

Leave a Comment

Your email address will not be published. Required fields are marked *