Operations | Sololearn: Learn to code for FREE!
0

# Operations

what ist the difference between && and & or between| and || ?

22nd Nov 2016, 7:16 PM
Ozan Karataş
3 Respuestas
+ 4
Logical operators: OR || takes two conditionals, return true if EITHER is true AND && takes two conditionals, return true if BOTH are true Bitwise operators: work on the bit level, compare each bit that build a value and act accordingly i will use small values which can be represented with 4 bits only. we will find x on each example OR | example: 5 | 3 = x 5 = 0101 3 = 0011 x = 0111 = 7 (bits in x are set by the bits of 5,3) AND & example: 5 & 3 = x 5 = 0101 3 = 0011 x = 0001 = 1
22nd Nov 2016, 7:37 PM
Burey
+ 3
"|" and "&" work on more than just booleans, while "&&" and "||" work only on booleans. While "&&" and "||" evaluates both sides of the operation, the others don't. In a && operation for example, if the left side value is false, then it'll short circuit and cease the evaluation. But in a & evaluation, always evaluate both sides, making possible side-effects. Examples: int a = 0; if(a == 9 && ++a == 9){} Console.Write(a) //Output: 0 ------------------ int a = 0; if(a == 9 & ++a == 9){} Console.Write(a) //Output: 1 I'am sorry if my english is not good enough to explain better.
22nd Nov 2016, 8:19 PM
Iván
0
thank you for ur answer :)
23rd Nov 2016, 12:32 PM
Ozan Karataş
En tendencia hoy
HELP ME
2 Votes
Python
0 Votes
Hi I am new
1 Votes
A long time
0 Votes