ProgrammingHardTCS NQT · Infosys
uint32_t mask = 0; for (int i = 0; i <= 30; i += 3) mask |= 1u << i; How many set bits does mask have?
- A. 10
- B. 12
- C. 11
- D. 32
Correct answer: C. 11
The positions are 0, 3, 6, ..., 30, which are 11 values. Each one sets a distinct bit, so the popcount is 11.
More C Programming questions
- unsigned int v = (unsigned int)(-2); printf("%X", v); What is printed?
- int a[3] = {1, 2, 3}; int p = a; int (q)[3] = &a; printf("%d", (q + 2) + (p + 1)); What is printed?
- unsigned char x = 0; x--; What is x?
- Which statement about the return value of strcmp is true?
- For 4-bit masks (bits 0 to 3), how many masks have both bit 0 and bit 2 set?
- What is the value of (1ULL << 63) >> 62 for uint64t arithmetic?