C++ Operators

This article covers the various Operators in C++

An integral part of any programming language, operators help form the base of C++. Used for a wide variety of purposes such as comparison, assignment, logic gates and arithmetic operations, operators come in many different types.

Below we’ve categorized all these operators into their respective sections.

Arithmetic Operators

Arithmetic operators are used with numerical values to perform different mathematical operations on number. Listed in the table below are all the C++ Arithmetic Operators.

Name Operator Description
Addition+ The Sum of two numbers.
Subtraction Difference of two numbers.
Multiplication* Product of two numbers.
Division/ Division of two numbers.
Modulus% Remainder of the division of two numbers.
increment++ Increments the number by 1
decrementDecrements the number by 1

Assignment Operators

Probably the most commonly used, the Assignment Operators are used to assign values to variables. See the full list of C++ Assignment operations below and their regular equivalents.

Operator Example Equivalent
= x = 2 N/A
+=x += 2x = x + 2
-=x -= 2x = x - 2
*=x *= 2x = x * 2
/=x /= 2x = x / 2
\=x \= 2x = x \ 2
%=x %= 2x = x % 3
^=x ^= 2x = x ^ 2

Comparison Operators

Comparison Operators are used to compare the contents of one variable to the other. If the Comparison holds true, then the Boolean value “True” is returned. However if the comparison is false, then the Boolean value “False” is returned.

== Equals to
!= Not Equal to
> Greater than
>= Greater than or equals to
< Less than
<= Less than or equals to

Logical Operators

Logical operators allow a program to make a decision based on multiple conditions (variables). The values of these variables decide the flow of the program.

&&AndReturns true if both statements are true
||OrReturns true if one of the statements is true
!NotInverses the result. (True if False, False if True).

This marks the end of the C++ Operators article. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the article material can be asked in the comments section below.

Leave a Reply

Your email address will not be published. Required fields are marked *