ProgrammingHardTCS NQT · Infosys
uint32_t v = 0; for each digit d of the decimal string "4294967296", v = v * 10 + d; What is v at the end?
- A. 4294967295
- B. 1
- C. 4294967296
- D. 0
Correct answer: D. 0
Unsigned arithmetic wraps modulo 2^32, and 4294967296 is exactly 2^32, so v becomes 0. Parsing large numbers into fixed-width unsigned types needs an explicit overflow check.
More C Programming questions
- Using fib-like recursion where a stair can be climbed by 1 or 2 steps, the number of ways for 10 stairs is the recursion W(n) = W(n-1) +…
- What is sizeof "hi" in C?
- For unsigned a and b greater than 0 stored in uint32t, which test correctly detects that a b overflows?
- char words[] holds strings and must be sorted by length first and then alphabetically using qsort. Which comparator is correct?
- char buf[4]; int n = snprintf(buf, sizeof buf, "%d", 12345); What is n?
- uint8t x = 0xB7; uint8t y = x | (x + 1); What is y?