ProgrammingVery hardCompetitive 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 x = 0x1F;
    uint8_t r = (uint8_t)((x << 4) | (x >> 4));
    printf("%d", r);
}
  1. A. 31
  2. B. 15
  3. C. 244
  4. D. 241

Correct answer: D. 241

Swapping the two nibbles of 0x1F gives 0xF1, which is 241. The left shift is truncated to 8 bits by the cast.

More C Programming questions

Exams that ask this topic