C++ language

Previous Home Next

An expression is a combination of operators, constants and variables. It also include function call which return values. An expression may include one or more operators. The operator in C++ are:

Arithmetic operators

Operator name Syntax Prefix Suffix
Basic assignment a = b
Addition a + b
Subtraction a - b
Unary minus -a
Unary plus +a
Multiplication a * b
Division a / b
Modulo (remainder) a % b
Increment ++ ++a a++
Decrement -- --a a--

Comparison operators/ Relational operators

Operator name Syntax
Equal to a ==b
Not equal to a !=b
Greater than a > b
Less than a > b
Greater than or equal to a >=b
Less than or equal to a <=b

Logical operators

Operator name Syntax
Logical negation (NOT) !a
Logical AND a && b
Logical OR a || b

Bitwise operators

Operator name Syntax
Bitwise NOT ! a
Bitwise AND a & b
Bitwise OR a | b
Bitwise XOR a ^ b
Bitwise left shift a << b
Bitwise right shift a >>b

Compound-assignment operators

Operator name Syntax
Addition assignment a += b
Subtraction assignment a -= b
Multiplication assignment a *= b
Division assignment a /= b
Modulo assignment a %= b
Bitwise AND assignment a &= b
Bitwise OR assignment a |= b
Bitwise XOR assignment a ^= b
Bitwise left shift assignment a <<=b
Bitwise right shift assignment a >>=b
Type of Expression
  • Constant Expression
  • 20
  • Integer Expression
  • m+n-2
    29+int (222.3)
  • Float Expression
  • m+n
    294+float (2224)
  • Pointer Expression
  • &m
  • Relational Expression
  • a+b==c+d
  • Logical Expression
  • a>b && x==1098
    x==200 ||y==20
  • Bitwise Expression
  • a>>1098
Previous Home Next