Блог пользователя luuchv

Автор luuchv, история, 10 лет назад, По-английски

For example, in Code::Block "2 and 3 = 1" while "2 & 3 = 2" I don't know what's the different between 'and' and '&'. Please explain for me. Thank you.

  • Проголосовать: нравится
  • -17
  • Проголосовать: не нравится

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

'and' is logical operator. If both operands are non-zero then 'and' will return 1 else 0. It is equivalent to && operator.

& is bitwise operator. Example

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

and keyword is an alternative of logical-and (&&) and not bitwise-and (&)

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

and — logic operator ( 2 and 3) = (true and true) = true = 1

& — bit operator (2 & 3) = binary(10 & 11) = binary(10) = 2