ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
int a = -1;
unsigned int b = 1;
if (a < b) printf("less");
else printf("not less");- A. Compilation error
- B. Undefined behaviour
- C. less
- D. not less
Correct answer: D. not less
In a comparison between int and unsigned int, the int is converted to unsigned: -1 becomes UINT_MAX (4294967295 for 32 bits), which is greater than 1. So it prints not less. Compilers warn about this signed/unsigned comparison.
More C Programming questions
- What is printed? c float f = 0.1f, g = 0.5f; printf("%s ", f == 0.1 ? "eq" : "ne"); printf("%s", g == 0.5 ? "eq" : "ne");
- On a little-endian machine with 4-byte int and ASCII, what is printed? c union { int i; char c; } u; u.i = 0x41424344; printf("%c", u.c);
- What is printed? c void swap(int x, int y) { x ^= y; y ^= x; x ^= y; } ... int a = 7; swap(&a, &a); printf("%d", a);
- On a two's-complement machine, what is printed? c printf("%d %d", 40 & -40, 40 & (40 - 1));
- For a signed int n on a two's-complement machine, how many of these are correct? (i) (n & (n - 1)) == 0 is true for every positive power…
- What is printed? c #define DOUBLE(x) x + x printf("%d", 10 / DOUBLE(5) 2);