Tokens In C++

 Tokens in C++

In C++, the smallest individual unit in a program are known as tokens, C++ has the following tokens:

  • Keywords
  • Identifiers
  • Constants
  • Strings
  • Operators
A C++ program is made using this tokens, white space (space, tabs, and newline) and the syntax of the language. Almost all the C++ tokens are same as in the C language with the exception of some addition and minor modification.

  • Keywords
Keywords are certain reserved words or identifiers, which cannot be used as a variable name, and other user defines program elements. The bellow is the list of C++ Keywords.


There are total 63 Keywords in C++ many of the Keywords are common in both C and C++, and some are added to increase the functionality and features.

  • Identifiers
Identifiers refers to the names of the variables, functions, array, classes, objects, etc. that a programmer creates, which are the fundamental requirement of any programming language. Each has its own rules for naming these identifiers, the following are the rules for naming the identifiers in C++.
  • Only alphabetic characters, digits and underscore are allowed.
  • The name should start with the alphabet or underscore.
  • Uppercase and lowercase letters are distinct.
  • Keywords cannot be used as the identifier name.
The only difference between the C and C++ identifiers is the limit of length a name. C recognizes the first 32 character in a name whereas C++ has no limit on the length all the characters are significant in the name.
  • Constants
Constants refers to the fixed values that do not change during the execution of the program. C++ supports several types of literals constants, they include integer, characters, floating point numbers and strings. Literal constants do not have memory location.
Examples:

123 // integer literal
45.45         // floating point integer
024         // octal numbers
“Hello”         // string literals
‘A’         // character literals
L’ab’         // wide character constant

The wchar_t type is a wide-character literal introduced by the ANSII C++ and is intended for character set that cannot fit in character into a single byte. Wide-character begins with the letter L.
  • Strings

Strings are just the array of characters ending with null character (‘\0’), the null character indicates the end of the string. Strings are always enclosed in double quotes (“ ”), and the characters are enclosed in single quotes (‘ ‘).

char string[] = {‘T’, ‘h’, ‘e’, “ “, ‘C’, ‘r’, ‘e’, ‘w’, ’\0’};

char string[] = “The Crew”;

  • Operators
Operators are symbols used to perform certain operation, the items upon which the operators perform operation are known as operands. Depending on the number of operands that an operator can act upon, operators can be classified as follows:
  • Arithmetic operator (+, -, *, /, %)
  •  Logical operator (&&, ||, !)
  • Relational operator (<, <=, >, >=, ==, !=)
  •  Assignment operator (=, +=, -=, *=, /=, %=)
  • Conditional operator (expression ? expression : expression)
  • Bitwise operator (&, |, ^, ~, <<, >>)

Comments

Popular posts from this blog

Datatypes In C++

call by value, pointer, reference

Operators in C++