ProgrammingHardProduct company OA
Assume 32-bit unsigned int. What is printed?
Assume 32-bit unsigned int. What is printed?
unsigned int u = 1u << 31;
printf("%u %u", u >> 31, (u >> 30) | (u >> 28 & 1));- A. 1 2
- B. 1 10
- C. 1 3
- D. 0 2
Correct answer: A. 1 2
u has only bit 31 set, so u >> 31 = 1 and u >> 30 = 2. In u >> 28 & 1 the shift binds first: (u >> 28) & 1 = 8 & 1 = 0, so the OR leaves 2. '10' forgets the & 1 (2 | 8).
More C Programming questions
- What is printed? c int x = 5, s = 0; switch (x) { default: s += 1; case 1: s += 10; case 2: s += 100; break; case 3: s += 1000; }…
- What is f in the declaration below? c int ((f)(int))[3];
- What is printed? c char s[10] = "abc"; char t[] = "xyz"; strncat(s, t, 2); printf("%s %zu %d", s, strlen(s), strncmp(s, "abcx", 4) == 0);
- What is printed? c char s[] = {"alpha", "beta", "gamma", "delta"}; char p = s; p += 2; printf("%c ", p); printf("%c ", ((p - 1) + 2))…
- What is printed? c int c = 0; int g(int n) { c++; if (n <= 2) return 1; return g(n - 1) + g(n - 2) + g(n - 3); } int main(void) { int r =…
- Assume 32-bit unsigned int. What is printed? c unsigned f(unsigned x) { return (x & 0x55555555u) << 1 | (x >> 1) & 0x55555555u; }…