Programming Fundamentals · Interview question

In if (x & 0x01 == 0), which operator runs first?

A strong answer

== runs first because it has higher precedence than the bitwise &. So the expression parses as x & (0x01 == 0), which is x & 0, which is always 0, the branch never runs. Almost certainly not what was intended. The fix is parentheses: if ((x & 0x01) == 0). This precedence quirk is a top source of subtle bugs in bit-manipulation code, which is why senior C programmers reach for parentheses whenever bitwise operators meet comparison operators.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Operators

Everything between the variables: the symbols that combine, compare, and change values. Learn the four families and the precedence rules that bite.

More Operators questions

Browse all 472 interview questions