Operators and Punctuators

Operators and Punctuators

Arithmetic, comparison, logical, bitwise, access, cast, and punctuation tokens across C and C++.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

Operators and Punctuators

Arithmetic operators

Comparison operators

Logical operators

Bitwise operators

Assignment operators

Access and call operators

Control-oriented tokens

Punctuation and separators

Operator overloading in C++

C++ allows many operators to be overloaded, including:

Not overloadable include:

Practical guidance

Small worked example

struct Point {
	int x{};
	int y{};
};

int main() {
	Point p{3, 4};
	int sum = p.x + p.y;
	bool large = sum >= 7 && p.x != 0;
	return large ? sum : 0;
}

This one short program touches member access ., arithmetic +, comparison >=, logical &&, inequality !=, assignment =, and the conditional operator ?:. That is a better operator reference example than a generic loop because the operators themselves are the point.

Operator-check habit

Example in practice

#include <iostream>

struct Point {
    int x{};
    int y{};
};

int main() {
    Point p{3, 4};
    int total = (p.x + p.y) * 2;
    bool large = total >= 10 && p.x != 0;
    std::cout << (large ? total : 0) << '\n';
}