ProgrammingHardProduct company OA
What is printed?
What is printed?
int t = 0;
for (unsigned i = 0; i < 16; i++)
for (unsigned x = i; x; x &= x - 1) t++;
printf("%d", t);- A. 30
- B. 32
- C. 16
- D. 64
Correct answer: B. 32
The inner loop runs once per set bit of i (each x &= x − 1 removes one). Over 0 to 15, each of the 4 bit positions is set in exactly half of the 16 numbers: 4 × 8 = 32.
More C Programming questions
- What is printed? c void s1(int a, int b) { int t = a; a = b; b = t; } void s2(int a, int b) { int t = a; a = b; b = t; } int main(void) {…
- Why does this fail to compile in C? c void f(int n) { static int k = n; }
- Which line correctly allocates space for a copy of a string pointed to by const char s?
- What is printed? c int a = 3, b = 0; int r = (a > b) + (a && b) 2 + (a || b) 4 + !b 8; printf("%d", r);
- What is printed? c int a[] = {5, 1, 4, 2, 3}; int lo = a, hi = a + 4; while (lo < hi) { if (lo > hi) lo++; else hi--; } printf("%td %d"…
- What is printed? c long memo[50]; int calls = 0; long f(int n) { calls++; if (n < 2) return n; if (memo[n]) return memo[n]; return memo[n]…