# AND OR NOT logical && || !

Printable View

• 09-03-2001
sballew
AND OR NOT logical && || !
I am still needing help understanding logical operators.

assuming i = 4 and j = 2 and k = -2
what do the following yield???

Code:

```printf("%d ",  !i < j ); printf("%d", !!i < !j ); printf("%d ", i && j || k ); printf("%d", i < j || k );```
what does !i mean?
what does !!i mean?
what does !i < j mean?
what does !!i < !j mean?
what does i && j mean?
what does i && j || k mean?

I am confused. When I input the above code in and compiled and ran, I got a result of [size=huge]1[/size] for each print function called.

??
• 09-03-2001
Stoned_Coder
what does !i mean?

well if i is true (anything other than 0) then !i (not i) is false(0) and vice-versa.

what does !!i mean?

not not i so if i is true not not i is true.

what does !i < j mean?

if i is true then !i becomes false and is it less than j? will be a true or false answer.

what does !!i < !j mean?

i think you can do this one now.

what does i && j mean?

are i and j both true. If so true else false.

what does i && j || k mean?

the result of i && j is then ored with k.or will produce true if one or both of its operands are true.

there is a thread on the c++ board about bitwise operators. Read that everything that applies to bits applies to boolean logic just on a slightly different scale.(with logical operators we are not testing/setting individual bits).
• 09-03-2001
minime6696
Im simpler terms...
Basically, read it in english outloud, and you will understand...

Like this:

!i > j

not i is greater than j
(!i) > j

Well !i will only return a true or a false : false if i is true, and true is i is false.

(!i) is greater than j
The revearse boolean of i is greater than j.

Assuming i is nonzero and j is 6:

1 > 6
This will return false.

SPH

P.S. Few im finding myself ending my sentances with ';' instead of '.';