Practice mode C Language

What is printed by this C code: printf(“%d”, 6 & 3 == 3);?

Correct answer B. 0

Explanation

Equality operators have higher precedence than bitwise &, so the expression is 6 & (3 == 3), which is 6 & 1. Binary 110 AND 001 is 0. Someone expecting (6 & 3) == 3 would compute 2 == 3 and still get 0 by a different route, but would give 2 if they forgot the comparison. Always parenthesise bit tests, as in (x & MASK) == MASK.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.