# Lession - #41 C++ Operators

An operator is an symbol that advises the compiler to perform explicit mathematical or logical controls. C++ is wealthy in underlying operators and give the accompanying sorts of operators −

• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Misc Operators

#### Arithmetic Operators

Assume variable A holds 10 and variable B holds 20, then −

Operator Description Example
+ Adds two operands A + B will give 30
- Subtracts second operand from the first A - B will give -10
* Multiplies both operands A * B will give 200
/ Divides numerator by de-numerator B / A will give 2
% Modulus Operator and remainder of after an integer division B % A will give 0
++ Increment operator, increases integer value by one A++ will give 11
-- Decrement operator, decreases integer value by one A-- will give 9

#### Relational Operators

Operator Description Example
== Checks if the values of two operands are equal or not, if yes then condition becomes true. (A == B>
is not true.
!= Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (A != B>
is true.
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B>
is not true.
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B>
is true.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B>
is not true.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B>
is true

#### Logical Operators

Assume variable A holds 1 and variable B holds 0, then −

Operator Description Example
&& Called Logical AND operator. In the event that both the operands are non-zero, condition becomes true. (A && B>
is false.
|| Called Logical OR Operator. In the event that any of the two operands is non-zero, condition becomes true. (A || B>
is true.
! Called Logical NOT Operator. Use to switches the logical condition of its operand. In the event that a condition is true, Logical NOT operator will make false. !(A && B>
is true.

#### Bitwise Operators

Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ are as follows −

p q p & q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1

#### Assignment Operators

Operator Description Example
= Simple assignment operator, Assigns values from right side operands to left side operand. C = A + B will allocate worth of A + B into C
+= Add AND assignment operator, It adds right operand to the left operand and allot the outcome to left operand. C += An is identical to C = C + A
-= Subtract AND assignment operator, It takes away right operand from the left operand and allocate the outcome to left operand. C - = An is comparable to C = C - A
*= Multiply AND assignment operator, It multiplies right operand with the left operand and allocate the outcome to left operand. C *= An is comparable to C = C * A
/= Divide AND assignment operator, It isolates left operand with the right operand and allocate the outcome to left operand. C/= An is comparable to C = C
%= Modulus AND assignment operator, It takes modulus utilizing two operands and relegate the outcome to left operand. C %= An is comparable to C = C % A
<<= Left shift AND assignment operator. C <<= 2 is same as C = C << 2
>>= Right shift AND assignment operator. C >>= 2 is same as C = C >> 2
&= Bitwise AND assignment operator. C &= 2 is same as C = C and 2
^= Bitwise exclusive OR and assignment operator. C ^= 2 is same as C = C ^ 2
|= Bitwise comprehensive OR and assignment operator. C |= 2 is same as C = C | 2

#### Misc Operators

Sr.No Operator and Description
1 sizeof
sizeof operator returns the size of a variable. For instance, sizeof(a>
, where 'a' is integer, and will bring 4 back.
2 Condition ? X : Y
Condition operator (?>
. On the off chance that Condition is valid, it returns value of X in any case returns value of Y.
3 ,
Comma operator makes an arrangement of activities be performed. The worth of the whole comma articulation is the value of the last articulation of the comma-isolated list.
4 . (dat>
and - > (arrow>

Part operators are utilized to reference individual individuals from classes, structures, and unions.
5 Cast
Casting operators convert one data type to another. For instance, int(2.2000>
would bring 2 back.
6 &
Pointer operator and returns the location of a variable. For instance &a; will give real location of the variable.
7 *
Pointer operator * is pointer to a variable. For instance *var; will pointer to a variable var.

object oriented java :OOP stands for Object-Oriented Programming. Procedural programming is about writing procedures or methods that perform operations on the data, while object-oriented programming is about creating objects that contain both data and methods.
C++ programming basics C++ is a powerful general-purpose programming language. It can be used to develop operating systems, browsers, games, and so on. C++ supports different ways of programming like procedural, object-oriented, functional, and so on. This makes C++ powerful as well as flexible.