Posted: Tue Nov 14, 2006 11:35 am Post subject: && vs & and || vs |
I'm sorry if this may seem as kind of a dumb question but I always keep forgeting about this. What is the difference between && and & and || and | ? I know one checked all conditions regardless if one of them was broken but which one is it?
I want my program to check 3 values and if one of them is incorrect (does not equal a supplied default one) then it goes to execute different code.
Thanks for any replies in advance.
Sponsor Sponsor
wtd
Posted: Tue Nov 14, 2006 12:24 pm Post subject: (No subject)
&& and || are logical. The others work on a bitwise basis.
raptors892004
Posted: Tue Nov 14, 2006 4:16 pm Post subject: (No subject)
wtd wrote:
&& and || are logical. The others work on a bitwise basis.
So what is the difference between && and & (it would be the same for || and |)? That was my question (I may have not expressed it too clearly though).
Andy
Posted: Tue Nov 14, 2006 4:25 pm Post subject: (No subject)
okay, bitwise or will or every single bit of two given binary strings. where as logical or will only give you 0 or 1
andy_tok
Posted: Tue Nov 14, 2006 4:54 pm Post subject: (No subject)
&& and || are short-circuits while & and | are not.
Sometimes short-circuit is useful.
Exp. (x!=0)&&(x++>10)
if x is 0, then the increment will not occur
if you want x++ to be implemented in all situations then use (x!=0)&(x++>10)
Andy
Posted: Tue Nov 14, 2006 5:13 pm Post subject: (No subject)
the short circuit aspect is a result of bitwise/logical characteristics. it's not by itself, a specific feature.
r.3volved
Posted: Tue Nov 14, 2006 6:55 pm Post subject: (No subject)
Basically what they're telling you is to look up the difference between, and definitions for bitwise and logical operators. You won't understand what they're used for if you don't understand why they're used.