ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint8_t a = 0xB6;
    uint8_t b = (uint8_t)(a << 3);
    uint8_t c = a >> 5;
    uint8_t d = (uint8_t)~a;
    printf("%d %d %d", b, c, d);
}
  1. A. 176 5 73
  2. B. 48 5 73
  3. C. 176 22 73
  4. D. 176 5 74

Correct answer: A. 176 5 73

uint8_t operands are promoted to int, so a << 3 is 1456, and converting back to uint8_t keeps 1456 mod 256 = 176. ~a is -183 as an int, which reduces mod 256 to 73.

More C Programming questions

Exams that ask this topic