Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

if (k & 1) in c++?

if (k & 1)

printf("1");

else

printf("0");

if has no logical operator then how does it work.

2 Answers

Relevance
  • 6 years ago
    Favorite Answer

    The expression k & 1 is evaluated first.

    & is a bitwise AND operator, so this will yield 1 if the least significant bit in k is set, 0 otherwise.

    The result of the expression is then evaluated. If it is 0, then the if condition is false. If it is any other value, the if condition is true.

  • roger
    Lv 7
    6 years ago

    an if statement does not need a logical operator.

    It just looks for zero or non zero. Logical operators produce 1 or 0 depending if the expression is true of false..

    printf("%d %d",k&1,k==1);

Still have questions? Get your answers by asking now.