What is the point of the NOT operator?

You are currently browsing C ++ using this tutorial . He explains what the operator is ! NOT, but I don’t think I fully understand why I ever wanted to use it. Can someone explain?

+5
source share
12 answers

Well, you want to divide the sum of two numbers by a third so that you can do this if the third number is not equal to zero.

    #include <iostream>
    using namespace std;
    int main()
   {
    int a,b,c,sum;
    cin >> a >> b >> c;
    sum = a+b;
    if (c!=0) //which is equivalent to if(!c)
    cout << sum/c;
   }

I used a simple example to quickly understand it. Now everything is all right? Regards and good luck in your studies.

+1
source

The operator !is useful if you want to verify that the condition is not currently satisfied.

, , :

bool subsystem_is_initialized();
void subsystem_initialize();

, , not.

if (!subsystem_is_initialized())
    subsystem_initialize();

, boolean. , , ( ), ( ) ( NANDs, , ).

, , ++, .

+13

( , ), , . , :

if (!test_something())
  do_something();

if (test_something()) {
} else
  do_something();

. , ++, , .

+5

, true/false , .

// Ensure that the thing is NOT red.
if (thing_is_red() == false)
    ...
if (!thing_is_red())
    ...
+5

! bool. , . :

 if (!existInArray(A, i))

, i .

+2

! NOT NOT.

, NOT , x , !x . .

, . , - , , .

+2

:

NOT: NOT . TRUE, FALSE, FALSE, TRUE.

, NOT , ( )

like && and || ` , :

  result = operand1  && operand2
  result = operand1  || operand2

:

  result = !operand1 

id operand1 = True, False, operand1 = False True.

:

, NOT (1) 0, NOT (0) 1. NOT ( , ) 0. C ++ NOT !. NOT AND OR.

c/++ 0 False Non 0 True.

!

(1).

!( 1 || 0 )  

, 1 || 0 is 1 true, NOT 0 False:

    !( 1 || 0 )  
=>  ! (1)     
=>  0  that is false

: || ! NOT.

    !( 1  || 0 )  
    ^      ^
    NOT   OR  

OR || , NOT

+2

, , std::istream:

int i;
std::cin >> i;
if ( ! std::cin ) {
    //  Something went wrong...
}

, isValid() isDone() ; GoF, :

for ( IteratorType i( init ); ! i.isDone(); i.next() ) {
    //  Do something with i.element()
}

contains,

if ( ! myMap.contains( key ) )

: , , :

bool found = false;
int current = 0;
while ( ! found && current != end ) {
    //  maybe set found...
}
+2

! , false true. == false == 0. :

if (p == NULL || p- > next!= NULL)

:

(! p || p- > next)

[, " " , , ].

+1

, NOT.

!. , ( ).

, ++, if ( ! ptr ), if ( ptr == NULL ), .

if ( ! (i % 2) ) ? , "?" / if, .

, , NOT bool . !, .

, , , strcmp. , #define, #define STRCMP_EQUAL 0 .., , if ( STRCMP_EQUAL == strcmp(str1, str2) ), , , , if ( ! strcmp(str1, str2) ).

+1

! ( ++). (.: ::)! . . .

//A is empty if memeber size is 0, and no further operations are allowed on other members if
// class is empty.
class A{
int size;
int lot;
int price;
public:
   bool operator!()
  {
      if(lot)
       return true; 
      else
      return false;
  }
};

A AObj;

//Aobj has size greater than 0
if(!Aobj)
{
//code to Fill or reuse the object.
}
+1
source

Dot! The operator must make an expression that is false in the true expression. It is most often used as a replacement for == false or == 0. This often makes it easier to read the expression:

if (p == NULL || p-> next! = NULL)

matches with:

if (! p || p-> next)

[Good, so it’s “easier to read” here, obviously, very subjectively].

+1
source

All Articles