ProgrammingHardProduct company OA
What is printed?
What is printed?
unsigned p = 0xB5;
p ^= p >> 4;
p ^= p >> 2;
p ^= p >> 1;
printf("%u", p & 1);- A. 5
- B. 1
- C. 3
- D. 0
Correct answer: B. 1
Each step folds the upper half onto the lower half with XOR, so bit 0 ends up as the XOR of all eight bits, i.e. the parity. 0xB5 = 1011 0101 has five 1s, an odd number, so the result is 1. '5' is the bit count itself.
More C Programming questions
- Assume 2-byte short, 4-byte int and natural alignment. What is printed? c #include <stddef.h> struct R { char a; short b; char c; int d…
- What is printed? c int sum(int (r)[3], int n) { int s = 0; for (int i = 0; i < n; i++) s += r[i][i % 3]; return s; } int main(void) { int…
- What is printed? c int even(int n); int odd(int n) { return n == 0 ? 0 : even(n - 1); } int even(int n) { return n == 0 ? 1 : odd(n - 1)…
- What is printed? c char w[] = {"pear", "fig", "apple", "kiwi"}; for (int i = 0; i < 3; i++) for (int j = 0; j < 3 - i; j++) if…
- What is printed? c int score = 73; char g = score >= 90 ? 'A' : score >= 75 ? 'B' : score >= 60 ? 'C' : 'D'; printf("%c%d", g, g - 'A');
- Which of these statements about C (not C++) are true? (i) A const int variable at file scope is a constant expression, so it can size a…