# C++ Operators

• ##### Arithmetic Operators
OPERATOR DESCRIPTION EXAMPLE
• ##### Relational Operators(<,<=,>,>=,==,!=)
OPERATOR DESCRIPTION EXAMPLE
• ##### Logical Operators( AND, OR,  NOT ,&& , ||,  !)
OPERATOR DESCRIPTION EXAMPLE
• ##### Assignment Operator =
OPERATOR DESCRIPTION EXAMPLE
##### C++ Expression

Expressions are sequences of operators and operands that are used for one or more of these purposes:

• Computing a value from the operands.
• Designating objects or functions.
• Generating “side effects.” (Side effects are any actions other than the evaluation of the expression — for example, modifying the value of an object.)

Numeric Expression

A C++ expression involving Arithmetic Operators is called numeric expression. Any expression in C++ consists of operators and operands. Examples of C++ numeric expressions are given below:

 Expression Operator Operands 10 + 20 + 10 and 20 25 – 16 – 25 and 16 35 / 4.25 / 35 and 4.25 20 * 1.25 * 20.5 and 1.25 25 % 7 % 25 and 7 35 * 2 * 35 and 2

Pure Expression: An expression where all the operands belong to same data type.

Rule:          int operator int = int

float operator float = float

double operator double = double

Examples of pure expressions:

 Integer Type Floating Point Type 10 + 20 2.5 + 3.8 20 – 5 9.8 – 3.5 17 * 6 11.25 * 2.5 35 / 7 5.7 / 1.9 34 % 5 10.8 / 3.2

Mixed Expression: An expression where the operands belong to different data types.

Rule:          int operator char = int

char operator int = int

int operator float = float

float operator int = float

int operator double = double

double operator int = double

Examples of mixed expressions:

32 + ‘A’ = 97                      since ASCII code of ‘A’ is 65

‘t’ – 32 = 84                      since ASCII code of ‘t’ is 116

20.0 / 8 = 2.5

20 + 2.5 = 22.5

##### Precedence of  operators.
CATEGORY OPERATOR ASSOCIATIVITY
##### Value in a=12
 ++a is Pre-incrementIncrements value of a by 1, a’s value is 11a++ is Post-incrementIncrements value of a by 1, a’s value is 12
##### cout<<“Value in a=”<<a<<endl;
 –a is Pre-decrementDecrements value of a by 1, a’s value is 6a– is Post-deccrementDecrements value of a by 1, a’s value is 5
##### Displays decremented values stored in z

Next: C++ Input & Output