ProgrammingHardCompetitive coding (CP)

What is printed? Assume uint8t is 8 bits.

What is printed? Assume uint8_t is 8 bits.
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint8_t v = 0;
    v |= 1u << 3;
    v |= 1u << 6;
    v &= (uint8_t)~(1u << 3);
    v ^= 0xFF;
    printf("%d", v);
}
  1. A. 63
  2. B. 191
  3. C. 187
  4. D. 64

Correct answer: B. 191

After the steps v is 0x40, then XOR with 0xFF flips every bit to give 0xBF = 191. Skipping the final XOR leaves 64, and clearing the wrong bit gives different values.

More C Programming questions

Exams that ask this topic