Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

### rhezo's blog

By rhezo, history, 7 years ago,

I was solving this problem. I have a function go, which returns a boolean true or false. When I replace "|" with "||", I get AC, otherwise I get TLE on test 6. I get AC with "||" and "or", but TLE with "|". Can anyone tell me the difference between the three?

• +14

 » 7 years ago, # | ← Rev. 2 →   0 For booleans there is priority difference: http://en.cppreference.com/w/cpp/language/operator_precedenceCan you show your code? Possibly you use '|' and '&&' combination.
•  » » 7 years ago, # ^ |   0 AC CodeTLE CodeLook in the last line of go function.
 » 7 years ago, # |   +10 | is bitwise operator.|| and "or" are logical operator.As tyamgin said it could happen because of precedence. "The & and | operators have lower precedence than comparison operators. That means that x & 3 == 1 is interpreted as x & (3 == 1), which is probably not what you want." Source
•  » » 7 years ago, # ^ |   0 Thanks!
 » 7 years ago, # |   +37 First of all, || and or are identical, but there is a big difference between | and ||.|| is a boolean operator. a || b returns true or false. If a is non-zero, then the value of b is not checked (since the answer is guaranteed to be true).| is bitwise-or. a | b returns a number (which can then be cast to a boolean if you need to). This evaluates both a and b, and then computes the bitwise or of them.The most likely reason that || is not getting TLE is because it is not evaluating the second operand. This is especially true if the second operand is a complex function that has to be evaluated.