C++ Operators Reference šŸ“

beginner
16 min

C++ Operators Reference šŸ“

Welcome to our comprehensive guide on C++ Operators! This tutorial is designed for both beginners and intermediates, covering a wide range of topics in an easy-to-understand manner.

Table of Contents šŸŽÆ

  1. Arithmetic Operators

    • Addition (+)
    • Subtraction (-)
    • Multiplication (*)
    • Division (/)
    • Modulus (%)
    • Increment (++)
    • Decrement (--)
  2. Relational Operators

    • Equal (==)
    • Not Equal (!=)
    • Greater Than (>)
    • Less Than (<)
    • Greater Than or Equal (>=)
    • Less Than or Equal (<=)
  3. Logical Operators

    • AND (&&)
    • OR (||)
    • NOT (!)
  4. Assignment Operators

    • Assignment (=)
    • Addition Assignment (+=)
    • Subtraction Assignment (-=)
    • Multiplication Assignment (*=)
    • Division Assignment (/=)
    • Modulus Assignment (%=)
  5. Bitwise Operators

    • Bitwise AND (&)
    • Bitwise OR (|)
    • Bitwise XOR (^)
    • Bitwise NOT (~)
    • Bitwise Left Shift (<<)
    • Bitwise Right Shift (>>)
  6. Miscellaneous Operators

    • Address-of Operator (&)
    • Pointer Dereference Operator (*)

Quiz šŸ’”

Quick Quiz
Question 1 of 1

Which operator is used for the increment of a variable?


Arithmetic Operators šŸŽÆ

Arithmetic operators are used to perform mathematical operations. Let's explore each one.

Addition (+)

Adds two operands.

cpp
int a = 5; int b = 3; int sum = a + b; // sum = 8

Subtraction (-)

Subtracts one operand from another.

cpp
int a = 10; int b = 3; int difference = a - b; // difference = 7

Multiplication (*)

Multiplies two operands.

cpp
int a = 5; int b = 3; int product = a * b; // product = 15

Division (/)

Divides one operand by another.

cpp
int a = 10; int b = 3; float quotient = (float)a / b; // quotient = 3.33333

Modulus (%)

Calculates the remainder of a division operation.

cpp
int a = 10; int b = 3; int remainder = a % b; // remainder = 1

Increment (++) and Decrement (--) Operators

Increment increases the value of a variable by 1. Decrement decreases the value of a variable by 1.

cpp
int a = 5; a++; // a = 6 int b = 5; --b; // b = 4

Remember, there's more to learn about these operators and other topics in C++! Stay tuned for our next lessons. āœ…


Note: Always make sure to declare variables before using them in your code. This ensures there are no runtime errors.


Pro Tip: Use operators wisely to write clean, efficient, and easy-to-read code.