ProgrammingHardWipro · Cognizant pattern
Assume 32-bit int. What is printed?
Assume 32-bit int. What is printed?
int x = 5;
int y = x & -x;
printf("%d", y);- A. 5
- B. 4
- C. 1
- D. 0
Correct answer: C. 1
x & -x isolates the LOWEST set bit of x. 5 is 0101; -5 in two's complement is ...11111011; ANDing them gives 0001 = 1, which is exactly 5's lowest set bit (the '1' bit).
More C Programming questions
- Assume 32-bit int. What is printed? c unsigned char a = 200; unsigned char b = 100; unsigned char c = a + b; printf("%u", c);
- Assume 32-bit int. What is printed? c int flags = 0; flags |= (1 << 2); flags |= (1 << 5); flags &= ~(1 << 2); printf("%d", flags);
- 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);