ProgrammingVery hardGATE CS · Competitive coding (CP)

Assume int is 32 bits. What is printed?

Assume int is 32 bits. What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint8_t b = 0xF3;
    int e = (int)(b ^ 0x80u) - 0x80;
    printf("%d", e);
}
  1. A. 243
  2. B. -13
  3. C. -141
  4. D. -12

Correct answer: B. -13

XOR with 0x80 flips the sign bit of the 8-bit field, leaving 0x73 = 115, and subtracting 0x80 gives -13. Skipping the subtraction gives 115, and the wrong constant gives -12.

More C Programming questions

Exams that ask this topic