ProgrammingHardTCS NQT · Infosys pattern
Assume 32-bit int. What is printed?
Assume 32-bit int. What is printed?
int flags = 0;
flags |= (1 << 2);
flags |= (1 << 5);
flags &= ~(1 << 2);
printf("%d", flags);- A. 32
- B. 4
- C. 36
- D. 0
Correct answer: A. 32
Setting bit 2 and bit 5 gives 0b100100 = 36. Then &= ~(1<<2) clears bit 2 specifically (ANDing with everything-except-bit-2), leaving only bit 5 set: 0b100000 = 32.
More C Programming questions
- Assume 32-bit int. What is printed? c int a = -1; unsigned int b = a; printf("%u", b);
- What is printed? (Assume no overflow trapping.) c int f(int n) { if (n == 0) return 0; return n + f(n - 1); } int main(void) {…
- What is printed? c int mystery(int a, int b) { if (b == 0) return a; return mystery(b, a % b); } int main(void) { printf("%d", mystery(48…
- What is printed? (Assume int is 32 bits, two's complement.) c unsigned int a = 0xF0F0F0F0; unsigned int b = a >> 4; printf("%X", b);
- What is printed? (Assume int is 32 bits, two's complement, arithmetic right shift for signed negatives — the common but…
- What is printed? (Check if a number is a power of two.) c int isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; } int main(void) {…