ProgrammingHardGATE CS · TCS NQT

What is printed?

What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint8_t m = 0x0F;
    for (int i = 0; i < 8; i++)
        m = (uint8_t)((m << 1) | (m >> 7));
    printf("%d", m);
}
  1. A. 30
  2. B. 240
  3. C. 16
  4. D. 15

Correct answer: D. 15

Eight left rotations of an 8-bit value bring every bit back to its place, so m is unchanged at 15. Stopping after one rotation would give 30.

More C Programming questions

Exams that ask this topic