ProgrammingVery hardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned x[] = {4000000000u, 4000000000u, 4000000000u};
unsigned s = 0;
for (int i = 0; i < 3; i++) s += x[i];
printf("%u", s / 3);
}- A. 4000000000
- B. 1136688470
- C. 1136688469
- D. 3410065408
Correct answer: C. 1136688469
The sum 12000000000 wraps modulo 2^32 to 3410065408, and dividing by 3 gives 1136688469. The true average 4000000000 needs a 64-bit sum.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int c = 0; for (int i = 0, j = 10; i < j; i += 2, j--) c++; printf("%d", c); }
- char b[5]; int n = snprintf(b, sizeof b, "%s", "abcdefgh"); printf("%s %d", b, n); What is printed?
- char buf[4]; int n = snprintf(buf, sizeof buf, "%d", 12345); printf("%d %s", n, buf); What is printed?
- char s[8] = "ab"; strncat(s, "cdefgh", 2); printf("%zu", strlen(s)); What is printed?
- char line[6]; fgets(line, sizeof line, stdin); / stdin holds the text 12345678 followed by a newline / printf("%zu", strlen(line)); What…
- char buf[7] = "hello"; memmove(buf + 1, buf, 5); printf("%s", buf); What is printed?