ProgrammingHardProduct company OA
Assume 32-bit unsigned int. What is printed?
Assume 32-bit unsigned int. What is printed?
unsigned int n = 5;
int count = 0;
for (unsigned int i = n; i < n + 3; i -= 2)
count++;
printf("%d", count);- A. 2
- B. Nothing: it loops forever
- C. 4
- D. 3
Correct answer: D. 3
i takes 5, 3, 1 (all below 8). Then 1 − 2 wraps to 4294967295, which is not below 8, so the loop stops after 3 passes. Unsigned wrap-around is well defined; the infinite-loop answer imagines i going negative.
More C Programming questions
- What is printed? c char w[][6] = {"red", "green", "blue"}; printf("%zu %zu %zu", sizeof(w), sizeof(w[1]), strlen(w[1]));
- What is printed? c int m = 0; long p(long b, int e) { if (e == 0) return 1; long h = p(b, e / 2); m++; if (e % 2) { m++; return h h b; }…
- What is printed? c enum Flag { RED = 1, GREEN = RED << 1, BLUE = GREEN << 1, ALL = RED | GREEN | BLUE }; printf("%d %d", ALL, ALL & ~GREEN);
- What is printed? c void rev(char s, int i, int j) { if (i >= j) return; char t = s[i]; s[i] = s[j]; s[j] = t; rev(s, i + 2, j - 2); } int…
- Why are multi-statement macros usually written as #define M(x) do { ... } while (0)?
- What is printed? c #define INC(x) x++; x++ int a = 0, b = 0; if (a > 5) INC(b); printf("%d", b);