ProgrammingVery hardProduct company OA
Assume 32-bit int, two's complement. What is printed?
Assume 32-bit int, two's complement. What is printed?
int x = 7;
int y = -7;
printf("%d %d", x | y, x ^ y);- A. -1 14
- B. -1 -14
- C. 7 -14
- D. -7 14
Correct answer: B. -1 -14
7 is 0...0111, -7 is 1...1001 (two's complement). OR of these covers every bit that's 1 in either: since -7's upper bits are all 1, the OR is all 1s = -1. XOR: 0111 ^ ...1001 (lower nibble) = ...1110 pattern across all the differing upper bits too, which computes out to -14 exactly (a known identity-free numeric result from direct bit computation).
More C Programming questions
- What is printed? c int a = 0; for (int i = 0; i < 4; i++) { a |= (1 << i); } printf("%d", a);
- What is printed? c int x = 255; unsigned char y = (unsigned char)(x << 1); printf("%d", y);
- What is printed? c int x = 5, y = 9; int max = y ^ ((x ^ y) & -(x < y)); printf("%d", max);
- What is printed? c int x = 101; int y = (x >> 2) << 2; printf("%d", y);
- What is printed? c #include <stdio.h> int main(void) { int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (p)[3] = a; printf("%d %d", ((p + 1))[2]…
- Assume a 64-bit ABI with 4-byte int. What is printed? c #include <stdio.h> int main(void) { int a[4]; int p = a; char cp = (char )a…