CppOperators Overview

Operators Overview

An operator is a symbol that tells the compiler to perform a specific mathematical, logical, or structural operation. C++ has one of the richest operator sets of any mainstream language — this page is a map of every category, with dedicated pages that go deeper into arithmetic, relational and logical, bitwise, assignment, and precedence rules.

Operator Categories at a Glance

Category

Operators

Example

Arithmetic

      • / %

int sum = a + b;

Relational

== != > < >= <=

if (age >= 18) { ... }

Logical

&& || !

if (isValid && !isExpired) { ... }

Bitwise

& | ^ ~ << >>

flags |= FLAG_VISIBLE;

Assignment

= += -= *= /= %= &= |= ^= <<= >>=

total += 10;

Increment / decrement

++ --

counter++;

Member access

. -> :: *

obj.method(); ptr->field; Class::staticMember;

Other

sizeof, ::, ?:, comma (,)

sizeof(int); condition ? a : b;

Arithmetic Operators
Perform basic math: addition, subtraction, multiplication, division, and modulo (remainder). Integer division truncates instead of rounding, and % only works on integer types. See the dedicated **Arithmetic Operators** page for the full detail and common pitfalls.
Relational and Logical Operators
Relational operators compare two values and produce a bool result. Logical operators combine or invert boolean expressions and support short-circuit evaluation. See **Relational &amp; Logical Operators** for floating-point comparison pitfalls and signed/unsigned comparison gotchas.
Bitwise Operators

Operate directly on the individual bits of an integer's binary representation — useful for flags, masks, and low-level performance tricks. See Bitwise Operators for a full worked example using bit flags.

Assignment Operators
Store a value into a variable. Beyond plain =, C++ offers compound assignment operators that combine an operation with assignment in one step, like total += 10; instead of{' '} total = total + 10;. See **Assignment Operators** for the full table.
Increment and Decrement

CPP
int a = 5;
a++;   // postfix increment: use current value, then increment
++a;   // prefix increment: increment, then use new value
Member Access and Other Operators

Operator

Purpose

.

Access a member of an object

->

Access a member through a pointer

::

Scope resolution — access a namespace, class static member, or global

sizeof

Query the size in bytes of a type or object

?:

Ternary conditional expression — a compact if/else

,

Comma operator — evaluates left, discards it, evaluates and returns right

CPP
#include <iostream>

struct Point { int x; int y; };

int main() {
    Point p{3, 4};
    Point* ptr = &p;

    std::cout << p.x << std::endl;     // member access with .
    std::cout << ptr->y << std::endl;  // member access through a pointer with ->
    std::cout << sizeof(Point) << std::endl; // sizeof

    int max = (p.x > p.y) ? p.x : p.y; // ternary conditional
    std::cout << max << std::endl;
    return 0;
}
Note
This page is intentionally a map, not the full story — each category above has its own dedicated page covering edge cases, common mistakes, and worked examples in depth.