ProgrammingVery hardTCS NQT · Infosys
What is printed? Assume unsigned int is 32 bits.
What is printed? Assume unsigned int is 32 bits.
#include <stdio.h>
int main(void) {
unsigned s = 0;
for (unsigned i = 1; i <= 100000; i++)
s += i;
printf("%u", s);
}- A. 705082704
- B. 5000050000
- C. 705082703
- D. 4294967295
Correct answer: A. 705082704
The true sum 5000050000 wraps modulo 2^32, so the stored value is 5000050000 - 4294967296 = 705082704. An unsigned long long accumulator would print 5000050000.
More C Programming questions
- How many partitions of 5 are there? The program counts partitions of n into parts of size at most m. Compute with it. c #include <stdio.h>…
- What is printed? c #include <stdio.h> int main(void) { char c = 'A'; c += 32; printf("%c %d", c, c); }
- What is printed? c #include <stdio.h> int main(void) { int x = 2, r = 0; switch (x) { case 1: r += 1; case 2: r += 10; case 3: r += 100…
- How many loop iterations run? Compute with the program. c #include <stdio.h> int main(void) { unsigned x = 0xF00D; int c = 0; while (x) {…
- What is printed? c #include <stdio.h> int main(void) { int i = 5; do { i++; } while (i < 3); printf("%d", i); }
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { printf("%d %zu", 1 ? 'A' : 0, sizeof(1 ? 'A' : 0)); }