# OR statement in C

• 11-25-2009
Keylac
OR statement in C
Hi,

Is there such a thing as an OR statement in C?

For example:

If (x>0 OR x<10)
then.....

Thanks!
• 11-25-2009
Yes, replace the OR with || (AND is && in C)
• 11-25-2009
Keylac
Thank you!
• 11-25-2009
No problem, I'll bill you later. :)
• 11-25-2009
hilarius
Keylac, I assume you are a beginner (so am I). Pay attention to the double symbols: && and ||

You also have the single | and &, which are the bitwise operators for or and and.

You'll remember from boolean logics:

0 | 1 = 1
1 | 0 = 1
1 | 1 = 1
0 | 0 = 0

0 & 1 = 0
1 & 0 = 0
1 & 1 = 1
0 & 0 = 0

It's an often made beginner's mistake to confuse these operators (logical and bitwise), it 's comparable to

Quote:

if (x = 0)
• 11-25-2009
x2x3i5x
another thing ....

x=6 is often mistaken with x ==6.

x = 6 means, make x equal 6.

x == 6 means, "Is x equal to 6?"
• 11-25-2009
RockyMarrone
Quote:

Originally Posted by x2x3i5x
another thing ....

x=6 is often mistaken with x ==6.

x = 6 means, make x equal 6.

x == 6 means, "Is x equal to 6?"

I totally agree with this point, and this is a very good point to mention where most beginner does the mistake. in condition or loop people say something like x=6 means it will, always be true.

so to reduce what we can do just

do like this

Code:

`if (6 ==x)`
Then when ever by mistake we do like

Code:

`if (6 =x)`
it means the compiler will say than
Quote:

error: lvalue required as left operand of assignment
In my point of view we can do like this also
• 11-26-2009
Keylac
Thanks!
Thanks everyone for the great info!
• 11-26-2009
laserlight
Okay, now that you got the important, here's some fun trivia:

If your compiler supports the 1999 edition of the C standard sufficiently, you can #include <iso646.h> and use the or macro instead of ||. (<iso646.h> defines or to be || for you.) That said, there is probably no benefit for you in doing this.