ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned n = 2;
if (n - 3 < 5) puts("small");
else puts("big");
}- A. small
- B. big
- C. both
- D. neither
Correct answer: B. big
n - 3 is unsigned and wraps to 4294967295, which is not less than 5, so the program prints big. A signed analysis would wrongly predict small.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int idx = -1; int a[3] = {1, 2, 3}; unsigned u = (unsigned)idx; printf("%d", u < 3…
- What is printed? c #include <stdio.h> int f(void) { static int s = 5; return s++; } int main(void) { int a = f(), b = f(), c = f()…
- What is printed? Assume char is 1 byte, int is 4 bytes with 4-byte alignment. c #include <stdio.h> struct S { char a[5]; int b; }; int…
- What is printed? c #include <stdio.h> enum { A, B = 5, C }; int main(void) { printf("%d %d", C, A + B); }
- What is printed? c #include <stdio.h> int main(void) { int i = 0, n = 0; while (i++, i < 5) n++; printf("%d", n); }
- What is printed? c #include <stdio.h> int main(void) { int i = 0, c = 0; do { i++; if (i % 2) continue; c++; } while (i < 6); printf("%d"…