Which statement sets bit n of an unsigned integer x to 1 and leaves the other bits unchanged?
Correct answer D. x |= 1u << n;
Explanation
OR with a mask that has only bit n set forces that bit to 1 and leaves every other bit as it was, because OR with 0 changes nothing. x &= ~(1u << n) is the matching idiom for clearing the bit, and ^= toggles it, which clears it if it was already set. x &= 1u << n would clear all the other bits.
Answer checked How we write and check questions
Discussion