# Binary Operators Summary (C++)

Go Up to Binary Operators Index

These are the binary operators in Appmethod C++:

## Arithmetic Operators

Arithmetic Operator Description Arithmetic Operator Description
```+
```

```-
```

Binary minus (subtract)

```*
```

Multiply

```/
```

Divide

```%
```

Remainder (modulus)

## Bitwise Operators

Bitwise Operator Description Bitwise Operator   Description
```<<
```

Shift left

```>>
```

Shift right

```&
```

Bitwise AND

```^
```

Bitwise XOR (exclusive OR)

```|
```

Bitwise inclusive OR

## Logical Operators

Logical Operator Description
```&&
```

Logical AND

## Assignment Operators

Assignment Operator Description Assignment Operator Description
```=
```

Assignment

```*=
```

Assign product

```/=
```

Assign quotient

```%=
```

Assign remainder (modulus)

```+=
```

Assign sum

```-=
```

Assign difference

```<<=
```

Assign left shift

```>>=
```

Assign right shift

```&=
```

Assign bitwise AND

```^=
```

Assign bitwise XOR

```|=
```

Assign bitwise OR

## Relational Operators

Relational Operator Description Relational Operator Description
```<
```

Less than

```>
```

Greater than

```<=
```

Less than or equal to

```>=
```

Greater than or equal to

```==
```

Equal to

```!=
```

Not equal to

## Component Selection Operators

Component Selection Operator Description
```.
```

Direct component selector

``` ->
```

Indirect component selector

## Class Member Operators

Class Member Operator Description
```::
```

Scope access/resolution

Use the scope access (or resolution) operator :: (two colons) to access a global (or file duration) name even if it is hidden by a local redeclaration of that name.

```.*
```

Dereference pointer to class member

Use the .* operator to dereference pointers to class members.

The first operand must be a class type. If the type of the first operand is class type TFoo, or is a class that has been derived from class type TFoo, the second operand must be a pointer to a member of a class type TFoo.

```->*
```

Dereference pointer to class member

Use the ->* operator to dereference pointers to class members.

The first operand must be a pointer to a class type. If the type of the first operand is a pointer to class type TFoo, or is a pointer to a class derived from class type TFoo, the second operand must be a pointer to a member of class type TFoo.

### Example

The pointer-to-member operators are probably best explained with an example such as this one:

```#include <iostream>

class TFoo {
public:
void func() {
std::cout << __func__ << std::endl;
}
int data;
};

void (TFoo::*pmfn)() = &TFoo::func;
int TFoo::*pmd = &TFoo::data;

int main() {
TFoo foo;
TFoo *pfoo = &foo;

// Call func with foo/pfoo
(foo.*pmfn)();   // With object
(pfoo->*pmfn)(); // With pointer

// Set/read data with object and ptr respectively
foo.*pmd = 123;
std::cout << "data=" << pfoo->*pmd << std::endl;

return 0;
}
```

## Conditional Operators

Conditional Operator Description
```?:
```

Actually a ternary operator. For example: `a ? x : y` means "if a then x else y".

```,