assistance with Logical NOT Operator

I am new to c++ and I am not sure in what situation should I use the ! not operator? I know what it means and does but not sure how one would go about using it? Examples would be nice, and if you are going to say it`s fundamentally basic or I need an introductory programming book or whatever else could you at least point me in the right direction like books, videos, etc.
Let's say you have a function that returns a bool.

bool foo();

No, let's say you want to do something when that function returns true.

1
2
3
4
if (foo())
{
    // do something
}


Now let's say you want to do something when that function returns false. You can do it either of 2 ways:

1
2
3
4
5
6
7
8
9
if (! foo())
{
    // do something
}

if ((foo() == false)
{
    // do something
}


No let's say you have a variable that needs to contain true when foo() is false, or false when foo() is true:

bool notFoo = !foo();

There are ways to work around the not operator, but it frequently comes in quite handy.
Topic archived. No new replies allowed.