ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
unsigned parse(const char *s) {
unsigned n = 0;
while (*s) n = n * 10 + (unsigned)(*s++ - '0');
return n;
}
int main(void) {
printf("%u", parse("4294967297"));
}- A. 4294967297
- B. 1
- C. 0
- D. 2
Correct answer: B. 1
unsigned arithmetic wraps modulo 2^32, so 4294967297 becomes 4294967297 - 4294967296 = 1. Any value above 4294967295 wraps.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { long long x = (1LL << 40) + 5; printf("%d", (int)(x & 0xFFFFFFFFLL)); }
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { printf("%zu", sizeof('a')); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", ~5 & 0xF); }
- What is printed? c #include <stdio.h> int main(void) { unsigned char c = 254; int n = 0; while (++c) n++; printf("%d", n); }
- How many iterations does this binary search make to find 13 in the sorted array 0 to 15? Compute with the program. c #include <stdio.h>…
- n <= 10^5 values, each up to 10^9, must be summed. Which declaration is correct for the total?