Namespaces
Variants
Views
Actions

Logical operators

From cppreference.com
< cpp‎ | language
Revision as of 03:05, 5 March 2012 by Bazzy (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:cpp/language/sidebar Returns a boolean value.

Operator name Keyword Syntax Over​load​able Prototype examples (for Template:cpp)
Inside class definition Outside class definition
negation Template:cpp !a Yes Template:cpp Template:cpp
AND Template:cpp a && b Yes Template:cpp Template:cpp
inclusive OR Template:cpp a || b Yes Template:cpp Template:cpp
Notes
  • The keyword-like forms (and,or,not) and the symbol-like forms (&&,||,!) have exactly the same meaning everywhere they can occur
  • Operators Template:cpp and Template:cpp perform short-circuit evaluation when used with basic type but that is not true if overloaded ( as they behave as functions )

See also

Operator precedence

Common operators
assignment increment
decrement
arithmetic logical comparison member
access
other

a = b
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b

++a
--a
a++
a--

+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b

!a
a && b
a || b

a == b
a != b
a < b
a > b
a <= b
a >= b
a <=> b

a[...]
*a
&a
a->b
a.b
a->*b
a.*b

function call
a(...)
comma
a, b
conditional
a ? b : c
Special operators

static_cast converts one type to another related type
dynamic_cast converts within inheritance hierarchies
const_cast adds or removes cv-qualifiers
reinterpret_cast converts type to unrelated type
C-style cast converts one type to another by a mix of static_cast, const_cast, and reinterpret_cast
new creates objects with dynamic storage duration
delete destructs objects previously created by the new expression and releases obtained memory area
sizeof queries the size of a type
sizeof... queries the size of a parameter pack (since C++11)
typeid queries the type information of a type
noexcept checks if an expression can throw an exception (since C++11)
alignof queries alignment requirements of a type (since C++11)