ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
if (-1 < 1u) printf("yes");
else printf("no");- A. yes
- B. compile error
- C. undefined
- D. no
Correct answer: D. no
When int meets unsigned int, the int is converted to unsigned: −1 becomes UINT_MAX (4294967295 with 32-bit int), which is not less than 1. Mixing signed and unsigned in comparisons is a classic source of bugs (compilers warn with -Wsign-compare).
More C Programming questions
- What is printed? c int a = 0, b = 0; int x = (++a > 5) && (++b > 0); int y = (++a > 0) || (++b > 0); printf("%d %d %d %d", a, b, x, y);
- What is printed? c printf("%c %d %d", 'A' + 2, 'A' + 2, 'z' - 'a');
- What is printed? c unsigned char a = 250, b = 10, z = 0; int s = a + b; unsigned char t = a + b; z--; printf("%d %d %d", t, z, s);
- What is printed? c int x = 6; printf("%d %d", x & 2 == 2, (x & 2) == 2);
- What is printed? c int a = (1, 2, 3); int b = 5; b = (b + 1, b 2); printf("%d %d", a, b);
- What is printed? c void f(int n) { if (n > 0) { f(n - 1); printf("%d ", n); f(n - 2); } } int main(void) { f(3); }