ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
int n = 40; /* binary 101000 */
printf("%d %d %d", n & (n - 1), n & -n, (n & (n - 1)) == 0);- A. 32 8 1
- B. 39 8 0
- C. 32 40 0
- D. 32 8 0
Correct answer: D. 32 8 0
n − 1 = 100111, so n & (n − 1) clears the lowest set bit: 100000 = 32. n & −n keeps only the lowest set bit: 8. The result is 0 only for powers of two, so the test prints 0 for 40.
More C Programming questions
- What is printed? c int a[] = {3, 1, 4, 1, 5}; int sum(int n) { return n == 0 ? 0 : a[n - 1] + sum(n - 1); } int main(void) { printf("%d"…
- Assume a 64-bit LP64 ABI (4-byte int, 8-byte pointers and double, natural alignment). What is printed? c int a[3][4] = {{1, 2, 3, 4}, {5…
- Assume 32-bit int and two's complement. What is printed? c unsigned char a = 0x0F; unsigned char b = ~a; printf("%d %d %d %d %zu", ~a ==…
- Assume 32-bit int and 64-bit long long. What is printed? c int n = -1; unsigned int len = 3; long long big = -1; printf("%d %d %d %d", n <…
- Assume a 64-bit LP64 ABI (4-byte int, 8-byte pointers and double, natural alignment). What is printed? c struct A { char c; double d; int…
- What is printed? c #define SQ(x) x x #define MIN(a, b) ((a) < (b) ? (a) : (b)) int calls = 0; int next(void) { return ++calls; } int…