luuchv's blog

By luuchv, history, 10 years ago, In English

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.

  • Vote: I like it
  • -17
  • Vote: I do not like it

»
10 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

'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 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
10 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

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

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