is called a 'short circuit' operator and & is a 'long circuit'
it means that
(3 < 2 && 3 < 5)
it will resolve that 3 < 2 is false, and will not even try to evaluate 3 < 5
but
(3 < 2 & 3 < 5)
it will evaluate both expressions
2. when oprators are both integral(char, byte, short, int, long)
than
1 && 2 will not even make sense, because && works only with logacal expressions(those that spit out booleans)
but
1 & 2 makes perfect sence, because in context of two integers it acts as a bitwise operator
1 in binary is 0001
2 in binary is 0010
so 1 & 2 = 0011
which is 3
3. why it happens? i think, because under the hood booleans are integral type which look like 0001 - true and 0000 - false, that is why``` 3<2 & 1<2``` will evaluate all expressions, it will simple do bitwise AND of false(0000) and true(0001)
Обсуждают сегодня