# c++ operators

Operator | Description | Example |
---|---|---|

Arithmetic Operators | ||

= | Assignment | x=3; assigns 3 to x. |

+ | Addition of numbers, concatenation of Strings | 1+2 gives 3, “hel”+”lo” gives “hello” |

+= | Add and assign numbers, concatenate and assign Strings | x+=1; same as x=x+1; |

– | Subtraction | 2-1 gives 1 |

-= | Subtract and assign | x-=1; same as x=x-1; |

* | Multiplication | 2*3 gives 6 |

*= | Multiply and assign | x*=2; same as x=x*2; |

/ | Division | 10/2 gives 5 |

/= | Divide and assign | x/=2; same as x=x/2; |

% | Take remainder | 10%3 gives 1 |

%= | Take remainder and assign | x%=3; same as x=x%3; |

++ | Increment by one | x++; same as x=x+1; |

— | Decrement by one | x–; same as x=x-1; |

Comparison Operators | ||

> | Greater than | 3>2 gives true |

>= | Greater than or equal to | 3>=2 gives true, 2>=2 gives true |

< | Less than | 2<3 gives true |

<= | Less than or equal to | 2<3 gives true, 2<=3 gives true |

!= | Not equal to | 2!=3 gives true |

== | Boolean equals | 3==3 gives true |

Logical Operators | ||

! | Boolean NOT | !true gives false |

&& | Boolean AND | true&&true gives true, true&&false gives false |

|| | Boolean OR | true||true gives true, true||false gives true |

Bitwise Operators | ||

~ | Bitwise NOT | ~10001001 gives 01110110 |

| | Bitwise OR | 01010000 | 11001111 gives 11011111 |

|= | Bitwise OR and assign | x|=10001000; same as x=x|10001000; |

^ | Bitwise XOR | 11000011 ^ 11010001 gives 00010010 |

^= | Bitwise XOR and assign | x^11001100; same as x=x^11001100; |

& | Bitwise AND | 11001111&01010000 gives 01000000 |

&= | Bitwise AND and assign | x&=11001111; same as x=x&11001111; |

>> | Shift bits right | 10000100>>2 gives 100001 |

>>= | Shift bits right and assign | x>>=2; same as x=x>>2 |

<< | Shift bits left | 11110000<<2 gives 11000000 |

<<= | Shift bits left and assign | x<<=2; same as x=<<2; |

>>> | Unsigned bit shift right | 10000100>>2 gives 00100001 |

>>>= | Unsigned bit shift right and assign | x>>>=2; same as x=x>>>2 |

Other Operators | ||

?: | Ternary | max=(a>b) ? a : b; if a>b take a, else take b |

**Search within Codexpedia**

Custom Search

**Search the entire web**

Custom Search

Related Posts