ProgrammingHardGATE CS · TCS NQT

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 = 0x1C;
    int c = 0;
    for (int i = 7; i >= 0 && !((x >> i) & 1u); i--)
        c++;
    printf("%d", c);
}
  1. A. 2
  2. B. 4
  3. C. 5
  4. D. 3

Correct answer: D. 3

0x1C is 00011100, so the three top bits are zero before the first set bit. The loop counts those leading zeros.

More C Programming questions

Exams that ask this topic