๐Ÿ”ง Operators in C++

Shrey VohraShrey Vohra
4 min read

# Operators

In C++, operators are special symbols used to perform operations on variables and values. Operators in C++ are categorized based on the kind of operation they perform.


๐Ÿงฎ 1. Arithmetic Operators

Used for basic mathematical operations.

OperatorDescriptionExampleResult
+Additiona + bSum
-Subtractiona - bDifference
*Multiplicationa * bProduct
/Divisiona / bQuotient
%Modulus (remainder)a % bRemainder

๐Ÿ”„ 2. Increment and Decrement Operators

OperatorDescriptionExampleResult
++Increment by 1++a or a++a = a + 1
--Decrement by 1--a or a--a = a - 1
  • ++a: Pre-increment (increments first, then uses the value)[pehle increment karo fir istemaal karo]

  • a++: Post-increment (uses the value, then increments)[pehle istemaal karo fir increment karo]


๐Ÿงฑ 3. Relational (Comparison) Operators

Used to compare two values; returns a boolean (true or false).

OperatorDescriptionExampleResult
==Equal toa == btrue if equal
!=Not equal toa != btrue if not equal
>Greater thana > btrue if a > b
<Less thana < btrue if a < b
>=Greater or equala >= btrue if a โ‰ฅ b
<=Less or equala <= btrue if a โ‰ค b

๐Ÿง  4. Logical Operators

Used to combine multiple conditions.

OperatorDescriptionExampleResult
&&Logical ANDa > 5 && b < 10true if both are true
``Logical OR
!Logical NOT (negation)!(a == b)true if a != b

๐Ÿ“ฆ 5. Assignment Operators

Assign values to variables.

OperatorDescriptionExampleEquivalent To
=Assigna = 5โ€”
+=Add and assigna += 3a = a + 3
-=Subtract and assigna -= 2a = a - 2
*=Multiply and assigna *= 4a = a * 4
/=Divide and assigna /= 2a = a / 2
%=Modulus and assigna %= 2a = a % 2

๐Ÿง  6. Bitwise Operators

Operate on binary representations.

OperatorDescriptionExampleResult
&ANDa & bBitwise AND
``OR`a
^XORa ^ bBitwise XOR
~NOT (1โ€™s complement)~aBitwise NOT
<<Left shifta << 1Shifts bits left
>>Right shifta >> 1Shifts bits right

๐Ÿ”€ 7. Conditional (Ternary) Operator

A compact way to write if-else.

condition ? value_if_true : value_if_false;

๐Ÿ“Œ Summary Table

CategoryOperators
Arithmetic+, -, *, /, %
Relational==, !=, <, >, <=, >=
Logical&&, `
Assignment=, +=, -=, *=, /=, %=
Bitwise&, `
Unary++, --
Ternary? :
0
Subscribe to my newsletter

Read articles from Shrey Vohra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shrey Vohra
Shrey Vohra