C++ Tokens

C++ Tokens are the smallest individual units of a program.

Following are the C++ tokens : (most of c++ tokens are basically similar to the C tokens)

  • Keywords
  • Identifiers
  • Constants
  • Variables
  • Operators


The reserved words of C++ may be conveniently placed into several groups. In the first group we put those that were also present in the C programming language and have been carried over into C++. There are 32 of these, and here they are:

    auto   const     double  float  int       short   struct   unsigned
    break  continue  else    for    long      signed  switch   void
    case   default   enum    goto   register  sizeof  typedef  volatile
    char   do        extern  if     return    static  union    while

There are another 30 reserved words that were not in C, are therefore new to C++,
and here they are:

    asm         dynamic_cast  namespace  reinterpret_cast  try
    bool        explicit      new        static_cast       typeid
    catch       false         operator   template          typename
    class       friend        private    this              using
    const_cast  inline        public     throw             virtual
    delete      mutable       protected  true              wchar_t

The following 11 C++ reserved words are not essential when the standard ASCII character set is being used, but they have been added to provide more readable alternatives for some of the C++ operators, and also to facilitate programming with character sets that lack characters needed by C++.

    and      bitand   compl   not_eq   or_eq   xor_eq
    and_eq   bitor    not     or       xor


Identifiers refers to the name of variables, functions, arrays, classes, etc. created by the user. Identifiers are the fundamental requirement of any language.

Identifier naming conventions

  • Only alphabetic characters, digits and underscores are permitted.
  • First letter must be an alphabet or underscore (_).
  • Identifiers are case sensitive.
  • Reserved keywords can not be used as an identifier's name.


Constants refers to fixed values that do not change during the execution of a program.

    Declaration of a constant  :
    const [data_type] [constant_name]=[value];

Consider the example

#include <iostream.h>
int main()
	const int  max_length=100;	// 	integer constant
	const char choice='Y';		// 	character constant
	const char title[]="www.includehelp.com";	// 	string constant
	const float temp=12.34;		//  float constant

	cout<<"max_length :"<<max_length<<endl;
	cout<<"choice :"<<choice<<endl;
	cout<<"title :"<<title<<endl;
	cout<<"temp :"<<temp<<endl;
	return 0;


    max_length :100
    choice :Y
    title :www.includehelp.com
    temp :12.34


A variable is a meaningful name of data storage location in computer memory. When using a variable you refer to memory address of computer.

We know that in C, all variables must be declared before they are used, this is true with C++.

The main difference in C and C++ with regards to the place of their declaration in the program...

C requires all the variables to be defined in the beginning of scope.

C++ allows the declaration of a variable anywhere in the scope, this means that a variable can be declared right at the place of its first use.

    Syntax to declare a variable :
    [data_type] [variable_name];

Consider the example

#include <iostream.h>

int main()
	int a,b;
	cout<<" Enter first number :";
	cout<<" Enter second number:";

	int sum;	// declaration 
	/*this type of declaration will not allow in C*/
	cout<<" Sum is : "<<sum <<"\n";
	return 0;


    Enter first number :55
    Enter second number:15
    Sum is : 70

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.