[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/language/operator_logical [Back]  [Original]

cppreference.com
cppreference.com

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
(lvalue, rvalue, xvalue)
( )
-(C++11)
,
(C++11)
(C++11)
:
:  
:
:
:
:
:
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||b, a&&b, !a
a==b, a!=b, a<b, a>b, a<=b, a>=b, a<=>b ( C++20)
a[b], *a, &a, a->b, a.b, a->*b, a.*b
a(...), a,b, a?b:c
new
delete
throw
alignof
sizeof
sizeof...(C++11)
typeid
noexcept(C++11)
(C++17)
(C++20)
const_cast
static_cast
reinterpret_cast
dynamic_cast
: (T)a, T(a), auto(a), auto{a} ( C++23)
 

.

​​ ( class T)
not a

!a

bool T::operator!() const; bool operator!(const T &a);
a and b

a && b

bool T::operator&&(const T2 &b) const; bool operator&&(const T &a, const T2 &b);
a or b

a || b

bool T::operator||(const T2 &b) const; bool operator||(const T &a, const T2 &b);

  • (and,or,not) (&&,||,!) ( )
  • bool, bool, , . ( void).
  • && || ( , ),

! rhs (1)
lhs && rhs (2)
lhs || rhs (3)
1)
2)
3)

bool, bool bool: , bool t() t.

bool prvalue.

true, false. false.

true, true. false. : false, .

true, ( ) true. : true, .

, .

a true false
!a false true
and a
true false
b true true false
false false false
or a
true false
b true true true
false true false

, :

<tbody> </tbody>
bool operator!(bool)
bool operator&&(bool, bool)
bool operator||(bool, bool)

#include <iostream>
#include <string>
int main()
{
    int n = 2;
    int* p = &n;
    //     bool
    if(    p && *p == 2   // "*p"    "p &&"
       || !p &&  n != 2 ) // ||    ,  &&
        std::cout << "true\n";

    //      bool
    std::cout << " ''  .\n";
    for(std::string line;    std::cout << "> "
                          && std::getline(std::cin, line)
                          && line != ""; )
        ;
}

:

true
 ''  .
> 
> 

operator&& operator|| , , :

valarray
(public - std::valarray)
valarray, valarray
( )
, ( fail())
(public - std::basic_ios) []


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

a(...)
a, b
a ? b : c

static_cast
dynamic_cast
const_cast cv
reinterpret_cast
C static_cast, const_cast reinterpret_cast
new
delete , new,
sizeof
sizeof... ( C++11)
typeid
noexcept , ( C++11)
alignof ( C++11)


Web Proxy Viewer  |  New URL  |  Original Page