×

Advanced Coding & Software Engineering Program

Duration: 1 Year (12 Months)

Join our premium 1-year program to master cutting-edge technologies and become an industry-ready Software Engineer!

Course Coverage

  • Languages: C, C++, Java, JavaScript, Python
  • Web Technologies: HTML, CSS, Bootstrap 5, MERN Stack, Full Stack Development
  • Databases: MySQL, MongoDB
  • Data Science Libraries: Pandas, NumPy
  • Development Tools: Visual Studio Code, IntelliJ IDEA, PyCharm, Postman, Git, GitHub
  • Cloud Platforms: Vercel, MongoDB Atlas

Program Highlights

  • Live Classes: Interactive sessions with real-time doubt resolution
  • Hands-On Sessions: Practical coding exercises to build real-world skills
  • Industry Experts: Learn from professionals with years of experience
  • Live Project: Work on real-world projects to apply your skills
  • Get Certificate: Earn a professional certificate upon program completion

Course Fee: Only ₹1020 / month
Limited Period Offer!

Operators in C++ – Complete Tutorial



Last Updated on: 5th Dec 2025 15:39:08 PM

Operators are special symbols used to perform operations on variables and values.
They are the building blocks of every program, allowing us to perform calculations, comparisons, assignments, logic checking, memory operations, and much more.

 

In real-life software systems—such as billing software, shopping apps, games, banking systems—operators are used everywhere.

Example: 

  • Billing software uses arithmetic operators for calculations.

  • Login systems use comparison operators to check passwords.

  • Games use logical operators to check conditions like "Is player alive AND has ammo?"

 

Understanding operators thoroughly makes you a strong and confident C++ programmer.

 

What Are Operators?

Operators in C++ are predefined symbols that instruct the compiler to perform specific mathematical, logical, or relational operations on data.
They work on "operands" (variables or values).

 

Example: in a + b,

  • a and b → operands

  • + → operator

 

 C++ supports unary, binary, and ternary operators. 

 

Types of Operators in C++

C++ provides a wide range of operators:

  1. Arithmetic Operators

  2. Relational Operators

  3. Logical Operators

  4. Assignment Operators

  5. Unary Operators

  6. Ternary (Conditional) Operator

  7. Bitwise Operators

  8. Increment & Decrement Operators

  9. Special Operators (sizeof, ?:, pointer operators)

  10. Operator Precedence & Associativity

Let’s understand each category one-by-one with full explanation.

 

1. Arithmetic Operators

Used for mathematical calculations.

Operator Description Example
+ Addition a + b
- Subtraction a - b
* Multiplication a * b
/ Division a / b
% Modulus (remainder) a % b

 

Example:

int a = 10, b = 3;
cout << a + b; // 13
cout << a % b; // 1

 

Real-Life Example:

Online billing system:

int price = 500, qty = 3;
int total = price * qty;

 

2. Relational Operators

Used to compare two values.

Operator Meaning
== equal to
!= not equal
> greater than
< less than
>= greater than or equal
<= less than or equal

 

Example:

int age = 18;
if (age >= 18) cout << "Eligible to Vote";

 

Real-Life Example:

Login system:

if (enteredPin == savedPin)
    cout << "Login Successful";

 

3. Logical Operators

Used for combining multiple conditions.

Operator Meaning Example
&& Logical AND cond1 && cond2
` Logical OR `
! Logical NOT !cond

 

Example:

if (age >= 18 && citizenship == true)
    cout << "Eligible";

 

Real-Life Example:

E-commerce check:

if (inStock == true && paymentSuccess == true)
    cout << "Order Placed";

 

4. Assignment Operators

Used to assign values.

Operator Meaning
= assign
+= add and assign
-= subtract and assign
*= multiply and assign
/= divide and assign
%= modulus and assign

 

Example:

int x = 5;
x += 3;  // x = 8

 

Real-Life Example:

Updating game score:

score += bonus;

 

5. Unary Operators

Work on a single operand.

Operator Meaning
+ Unary plus
- Unary minus
! NOT
~ Bitwise NOT
++ Increment
-- Decrement

 

6. Increment & Decrement Operators

Two types:

✔ Pre-increment: ++a

✔ Post-increment: a++

 

Example:

int a = 5;
cout << ++a; // 6
cout << a++; // 6 then a becomes 7

 

Real-Life Example:
Increasing cart quantity in shopping:

qty++;

 

7. Ternary Operator ?:

Short form of if-else.

 

Syntax:

condition ? value_if_true : value_if_false;

 

Example:

int age = 20;
string msg = (age >= 18) ? "Adult" : "Minor";

 

8. Bitwise Operators

Used for low-level operations, computer architecture, cryptography.

Operator Meaning
& AND
` `
^ XOR
~ NOT
<< left shift
>> right shift

 

Example:

int a = 5;  // 0101
int b = 3;  // 0011
cout << (a & b); // 1

 

9. Special Operators

sizeof operator

Returns size of data type.

cout << sizeof(int); // 4 bytes

 

Pointer Operators

  • & → address of variable

  • * → value at address

int a = 10;
int *p = &a;
cout << *p; // 10

 

Comma Operator

int x = (1, 2, 3); // result = 3

 

Scope Resolution Operator (::)

Used to access global variables or class functions.

::x;

 

10. Operator Precedence & Associativity

Operator precedence decides which operator executes first.

Example:

int result = 10 + 2 * 5;  // result = 20

 

Multiplication has higher precedence than addition.

 

Real-Life Practical Examples of Operators

 

Example 1: Shopping Cart Calculation

int price = 499;
int qty = 2;
int total = price * qty;

if (total >= 500 && total <= 2000)
    cout << "Eligible for Free Delivery";

 

Example 2: Student Marks Result System

int marks = 78;
string result = (marks >= 33) ? "Pass" : "Fail";
cout << result;

 

Example 3: ATM Login Verification

int pin = 1234, userPin;
cin >> userPin;

if (userPin == pin)
    cout << "Access Granted";
else
    cout << "Wrong Pin";


Example 4: Bitwise in IOT (Turning switch ON/OFF)

 

int flags = 0;
flags |= 1;   // Turn ON device 1

 

Practice Questions

  1. Write a program to calculate area of circle using operators.

  2. Take two numbers and print all arithmetic operations.

  3. Check whether a number is positive, negative, or zero using ternary.

  4. Swap two numbers using bitwise operator.

  5. Create a login system using relational and logical operators.

 

Conclusion

Operators are the heart of C++ programming.
Every program you write uses operators, whether you realize it or not.

 

From simple calculations to complex logic—billing systems, games, banking apps, traffic systems—operators make everything work.

 

Mastering them builds a strong programming foundation.

 

Keep practicing — you're doing amazing!

Happy Coding!    yes

 


Online - Chat Now
Let’s Connect

Inquiry Sent!

Your message has been successfully sent. We'll get back to you soon!

iKeySkills Logo