
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Hello World
- C++ Omitting Namespace
- C++ Tokens
- C++ Constants/Literals
- C++ Keywords
- C++ Identifiers
- C++ Data Types
- C++ Numeric Data Types
- C++ Character Data Type
- C++ Boolean Data Type
- C++ Variable Types
- C++ Variable Scope
- C++ Multiple Variables
- C++ Basic Input/Output
- C++ Modifier Types
- C++ Storage Classes
- C++ Numbers
- C++ Enumeration
- C++ Enum Class
- C++ References
- C++ Date & Time
- C++ Operators
- C++ Arithmetic Operators
- C++ Relational Operators
- C++ Logical Operators
- C++ Bitwise Operators
- C++ Assignment Operators
- C++ sizeof Operator
- C++ Conditional Operator
- C++ Comma Operator
- C++ Member Operators
- C++ Casting Operators
- C++ Pointer Operators
- C++ Operators Precedence
- C++ Unary Operators
- C++ Control Statements
- C++ Decision Making
- C++ if Statement
- C++ if else Statement
- C++ Nested if Statements
- C++ switch Statement
- C++ Nested switch Statements
- C++ Loop Types
- C++ while Loop
- C++ for Loop
- C++ do while Loop
- C++ Foreach Loop
- C++ Nested Loops
- C++ break Statement
- C++ continue Statement
- C++ goto Statement
- C++ Strings
- C++ Strings
- C++ Loop Through a String
- C++ String Length
- C++ String Concatenation
- C++ String Comparison
- C++ Functions
- C++ Functions
- C++ Multiple Function Parameters
- C++ Recursive Function
- C++ Return Values
- C++ Function Overloading
- C++ Function Overriding
- C++ Default Arguments
- C++ Arrays
- C++ Arrays
- C++ Multidimensional Arrays
- C++ Pointer to an Array
- C++ Passing Arrays to Functions
- C++ Return Array from Functions
- C++ Structure & Union
- C++ Structures
- C++ Unions
- C++ Pointers
- C++ Pointers
- C++ Dereferencing
- C++ Modify Pointers
- C++ Class and Objects
- C++ Object Oriented
- C++ Classes & Objects
- C++ Class Member Functions
- C++ Class Access Modifiers
- C++ Static Class Members
- C++ Static Data Members
- C++ Static Member Function
- C++ Inline Functions
- C++ this Pointer
- C++ Friend Functions
- C++ Pointer to Classes
- C++ Constructors
- C++ Constructor & Destructor
- C++ Default Constructors
- C++ Parameterized Constructors
- C++ Copy Constructor
- C++ Constructor Overloading
- C++ Constructor with Default Arguments
- C++ Delegating Constructors
- C++ Constructor Initialization List
- C++ Dynamic Initialization Using Constructors
- C++ Object-oriented
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
- C++ Virtual Function
- C++ Pure Virtual Functions & Abstract Classes
- C++ File Handling
- C++ Files and Streams
- C++ Reading From File
- C++ Advanced
- C++ Exception Handling
- C++ Dynamic Memory
- C++ Namespaces
- C++ Templates
- C++ Preprocessor
- C++ Signal Handling
- C++ Multithreading
- C++ Web Programming
- C++ Socket Programming
- C++ Concurrency
- C++ Advanced Concepts
- C++ Lambda Expression
- C++ unordered_multiset
Tokens in C++
C++ tokens are the smallest individual units of a program, that the compiler recognizes and processes. Together, they form the syntax of C++ code, the same as combining words to form a sentence.
C++ is the superset of C and so most constructs of C are legal in C++ with their meaning and usage unchanged. So tokens, expressions, and data types are similar to that of C.
Here are the following C++ tokens given below

Keywords
Keywords are reserved words which have fixed meaning, and its meaning cannot be changed. The meaning and working of these keywords are already known to the compiler. C++ has more numbers of keyword than C, and those extra ones have special working capabilities.
List of some commonly used keywords
- Control flow: if, else, switch, case, break, continue, return, goto
- Data types: int, char, double, float, bool, void, long, short
- Storage classes: static, extern, mutable, register, volatile
- Object-oriented programming: class, struct, public, private, protected, virtual, this, friend
- Other: namespace, using, typedef, const, sizeof, typeid, template, new, delete
Identifiers
Identifiers are names given to different entries such as variables, structures, and functions, classes, objects, arrays, etc. Also, identifier names should have to be unique because these entities are used in the execution of the program.
Identifier naming conventions
- Only alphabetic characters starting with a letter (A-Z, a-z), digits (0-9), and underscores (_) are permitted.
- The first letter must be an alphabet or underscore (_) not a number.
- Identifiers are case sensitive.
- Reserved keywords can not be used as an identifier's name.
Constants
Constants are like a variable, except that their value never changes during execution once defined.
There are two other different ways to define constants in C++. These are:
- By using const keyword
- By using #define preprocessor
Syntax to declare a constant
const [data_type] [constant_name]=[value];
Variables
A variable is a meaningful name of data storage location in computer memory. When using a variable you refer to memory address of computer.
Syntax to declare a variable
[data_type] [variable_name];
Example
#include <iostream> using namespace std; int main() { string name = "TutorialsPoint"; // String type variable int started_year = 2006; // Integer type variable double pi = 3.14159; // Double type variable char grade = 'A'; // Char type variable bool isActive = true; // Bool type variable return 0; }
Operators
C++ operator is a symbol that is used to perform mathematical or logical manipulations.
- Arithmetic Operators
- Increment and Decrement Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Misc Operators
Arithmetic Operators
Operator | Description |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulus |
Increment and Decrement Operators
Operator | Description |
---|---|
++ | Increment |
Decrement |
Relational Operators
Operator | Description |
---|---|
== | Is equal to |
!= | Is not equal to |
> | Greater than |
< | Less |
>= | Greater than or equal to |
<= | Less than or equal to |
Logical Operators
Operator | Description |
---|---|
&& | And operator. Performs logical conjunction of two expressions.(if both expressions evaluate to True, result is True. If either expression evaluates to False, the result is False) |
|| | Or operator. Performs a logical disjunction on two expressions.(if either or both expressions evaluate to True, the result is True) |
! | Not operator. Performs logical negation on an expression. |
Bitwise Operators
Operator | Description |
---|---|
<< | Binary Left Shift Operator |
!= | Is not equal to |
>> | Binary Right Shift Operator |
~ | Binary One's Complement Operator |
& | Binary AND Operator |
^ | Binary XOR Operator |
| | Binary OR Operator |
Assignment Operators
Operator | Description |
---|---|
= | Assign |
+= | Increments, then assign |
-= | Decrements, then assign |
*= | Multiplies, then assign |
/= | Divides, then assign |
%= | Modulus, then assigns |
<<= | Left shift and assigns |
>>= | Right shift and assigns |
&= | Bitwise AND assigns |
^= | Bitwise exclusive OR and assigns |
|= | Bitwise inclusive OR and assigns |
Misc Operators
Operator | Description |
---|---|
, | Comma operator |
sizeOf() | Returns the size of a memory location. |
& | Returns the address of a memory location. |
* | Pointer to a variable. |
? : | Conditional Expression |
Punctuation
Punctuation are the symbols, which are used to structure the code and separate different elements of the program.
Here is the following table of punctuation tokens in C++.
Punctuation | Description |
---|---|
Semicolon (;) | To end a statement |
Comma (,) | Separates variables, function arguments, etc. |
Period (.) | Access members of an object or class. |
Arrow (->) | Accesses members of an object pointed to by a pointer. |
Parentheses () | Used for grouping expressions or for function calls. |
Curly braces {} | Define blocks of code |
Square brackets [] | Denote array subscripts. |