ProgrammingVery hardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned n = 3, c = 0;
unsigned i = n - 1;
for (; i >= 0 && c < 10; i--)
c++;
printf("%u %u", c, i);
}- A. 10 2
- B. 3 0
- C. 10 4294967289
- D. 10 4294967288
Correct answer: D. 10 4294967288
i is unsigned, so i >= 0 is always true, and the loop stops only when c reaches 10. Starting at 2 and decrementing ten times leaves i = 2 - 10 mod 2^32 = 4294967288.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int a[3][4]; int n = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++)…
- Assume int is 4 bytes. What is printed? c #include <stdio.h> int main(void) { int a[10]; int p = &a[7], q = &a[2]; printf("%ld %ld"…
- Assume a pointer is 8 bytes and int is 4 bytes. What is printed? c #include <stdio.h> void f(int v[]) { printf("%zu ", sizeof v); } int…
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { char s[] = "hi0there"; printf("%zu %zu", sizeof s, strlen(s)); }
- What is printed? c #include <stdio.h> int A(int m, int n) { if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m…
- What is printed? c #include <stdio.h> unsigned long long g(unsigned n, unsigned long long acc) { return n == 0 ? acc : g(n - 1, acc 3 +…